Skip to content

Commit

Permalink
[systemd-sonic-generator] replace sscanf with strtol (sonic-net#15357)
Browse files Browse the repository at this point in the history
#### Why I did it
Avoid 'sscanf()' for number conversions. Its use can lead to undefined behavior, slow processing, and integer overflows. Instead prefer the 'strto*()' family of functions.

#### How I did it
replace sscanf with strtol
#### How to verify it
Manual test
  • Loading branch information
maipbui authored and sonic-otn committed Sep 20, 2023
1 parent fb0bafd commit 397546f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/systemd-sonic-generator/systemd-sonic-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ int get_num_of_asic() {
str_num_asic = strtok_r(NULL, "=", &saveptr);
strip_trailing_newline(str_num_asic);
if (str_num_asic != NULL){
sscanf(str_num_asic, "%d",&num_asic);
num_asic = strtol(str_num_asic, NULL, 10);
}
break;
}
Expand Down

0 comments on commit 397546f

Please sign in to comment.