Merge pull request #230 from liuchao173/patch-1

irqbalance: check the length of optarg
This commit is contained in:
Neil Horman 2022-07-19 08:20:08 -04:00 committed by GitHub
commit d88585832b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -124,6 +124,7 @@ static void parse_command_line(int argc, char **argv)
int opt;
int longind;
unsigned long val;
char *endptr;
while ((opt = getopt_long(argc, argv,
"odfjVi:p:s:c:l:m:t:e:",
@ -139,8 +140,8 @@ static void parse_command_line(int argc, char **argv)
exit(1);
break;
case 'c':
deepest_cache = strtoul(optarg, NULL, 10);
if (deepest_cache == ULONG_MAX || deepest_cache < 1) {
deepest_cache = strtoul(optarg, &endptr, 10);
if (optarg == endptr || deepest_cache == ULONG_MAX || deepest_cache < 1) {
usage();
exit(1);
}
@ -153,8 +154,8 @@ static void parse_command_line(int argc, char **argv)
foreground_mode=1;
break;
case 'i':
val = strtoull(optarg, NULL, 10);
if (val == ULONG_MAX) {
val = strtoull(optarg, &endptr, 10);
if (optarg == endptr || val == ULONG_MAX) {
usage();
exit(1);
}
@ -171,8 +172,8 @@ static void parse_command_line(int argc, char **argv)
if (!strncmp(optarg, "off", strlen(optarg)))
power_thresh = ULONG_MAX;
else {
power_thresh = strtoull(optarg, NULL, 10);
if (power_thresh == ULONG_MAX) {
power_thresh = strtoull(optarg, &endptr, 10);
if (optarg == endptr || power_thresh == ULONG_MAX) {
usage();
exit(1);
}
@ -189,14 +190,18 @@ static void parse_command_line(int argc, char **argv)
foreground_mode=1;
break;
case 't':
sleep_interval = strtol(optarg, NULL, 10);
if (sleep_interval < 1) {
sleep_interval = strtol(optarg, &endptr, 10);
if (optarg == endptr || sleep_interval < 1) {
usage();
exit(1);
}
break;
case 'e':
migrate_ratio = strtoul(optarg, NULL, 10);
migrate_ratio = strtoul(optarg, &endptr, 10);
if (optarg == endptr) {
usage();
exit(1);
}
break;
}
}