kopia lustrzana https://github.com/stlink-org/stlink
Check return values of sscanf()
Failing to check that a call to 'scanf' actually writes to an output variable can lead to unexpected behavior at reading time.pull/1306/head
rodzic
0a5cad7ee8
commit
8f97e62708
|
@ -160,8 +160,10 @@ int parse_options(int argc, char** argv, st_state_t *st) {
|
|||
|
||||
break;
|
||||
case 'p':
|
||||
sscanf(optarg, "%i", &q);
|
||||
if (q < 0) {
|
||||
if (sscanf(optarg, "%i", &q) != 1) {
|
||||
fprintf(stderr, "Invalid port %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (q < 0) {
|
||||
fprintf(stderr, "Can't use a negative port to listen on: %d\n", q);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,10 @@ void process_chipfile(char *fname) {
|
|||
(strncmp(buf, " ", strlen(" ")) == 0))
|
||||
continue; // ignore empty lines
|
||||
|
||||
sscanf(buf, "%63s %63s", word, value);
|
||||
if (sscanf(buf, "%63s %63s", word, value) != 2) {
|
||||
fprintf(stderr, "Failed to read keyword or value\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(word, "dev_type") == 0) {
|
||||
buf[strlen(buf) - 1] = 0; // chomp newline
|
||||
|
|
Ładowanie…
Reference in New Issue