Skip to content

Commit

Permalink
agent: Fix is_signal_handled failing parsing str to u64
Browse files Browse the repository at this point in the history
In the is_signal_handled function, when parsing the hex string returned
from `/proc/<pid>/status` the space/tab character after the colon
is not removed.

This patch trims the result of SigCgt so that
all whitespace characters are removed. It also extends the existing
test cases to check for this scenario.

Fixes: #4250
Signed-off-by: Champ-Goblem <cameron@northflank.com>
  • Loading branch information
Champ-Goblem authored and fidencio committed May 16, 2022
1 parent 832845a commit a0e2d26
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/agent/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,7 @@ fn is_signal_handled(proc_status_file: &str, signum: u32) -> bool {
warn!(sl!(), "parse the SigCgt field failed");
return false;
}
let mut sig_cgt_str = mask_vec[1];
if !sig_cgt_str.chars().nth(0).unwrap().is_numeric() {
sig_cgt_str = &sig_cgt_str[1..sig_cgt_str.len()-1]
}
let sig_cgt_str = mask_vec[1].trim();
let sig_cgt_mask = match u64::from_str_radix(sig_cgt_str, 16) {
Ok(h) => h,
Err(_) => {
Expand Down Expand Up @@ -2456,6 +2453,26 @@ OtherField:other
signum: 4,
result: true,
},
TestData {
status_file_data: Some("SigCgt:\t000000004b813efb"),
signum: 4,
result: true,
},
TestData {
status_file_data: Some("SigCgt: 000000004b813efb"),
signum: 4,
result: true,
},
TestData {
status_file_data: Some("SigCgt:000000004b813efb "),
signum: 4,
result: true,
},
TestData {
status_file_data: Some("SigCgt:\t000000004b813efb "),
signum: 4,
result: true,
},
TestData {
status_file_data: Some("SigCgt:000000004b813efb"),
signum: 3,
Expand Down

0 comments on commit a0e2d26

Please sign in to comment.