|
@@ -748,10 +748,24 @@ static char *add_serial(char *arg)
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
-void get_intrange(char *arg, int *val1, int *val2)
|
|
|
|
|
|
|
+bool get_intrange(const char *arg, int *val1, int *val2)
|
|
|
{
|
|
{
|
|
|
- if (sscanf(arg, "%d-%d", val1, val2) == 1)
|
|
|
|
|
- *val2 = *val1;
|
|
|
|
|
|
|
+ int pos, n;
|
|
|
|
|
+ // Is is unclear whether %n is counted in the returned value, so %n is doubled up to make 2 unambiguous
|
|
|
|
|
+ n = sscanf(arg, "%d%n%n -%d %n", val1, &pos, &pos, val2, &pos);
|
|
|
|
|
+ if (unlikely(arg[pos]))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ switch (n)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1: // %n not counted (only one number)
|
|
|
|
|
+ case 3: // %n counted
|
|
|
|
|
+ *val2 = *val1;
|
|
|
|
|
+ case 2: // %n not counted (two numbers)
|
|
|
|
|
+ case 5: // %n counted
|
|
|
|
|
+ return true;
|
|
|
|
|
+ default:
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static char *set_devices(char *arg)
|
|
static char *set_devices(char *arg)
|
|
@@ -770,7 +784,8 @@ static char *set_devices(char *arg)
|
|
|
nextptr = strtok(arg, ",");
|
|
nextptr = strtok(arg, ",");
|
|
|
if (nextptr == NULL)
|
|
if (nextptr == NULL)
|
|
|
return "Invalid parameters for set devices";
|
|
return "Invalid parameters for set devices";
|
|
|
- get_intrange(nextptr, &val1, &val2);
|
|
|
|
|
|
|
+ if (!get_intrange(nextptr, &val1, &val2))
|
|
|
|
|
+ return "Invalid device number";
|
|
|
if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
|
|
if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
|
|
|
val1 > val2) {
|
|
val1 > val2) {
|
|
|
return "Invalid value passed to set devices";
|
|
return "Invalid value passed to set devices";
|
|
@@ -782,7 +797,8 @@ static char *set_devices(char *arg)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
while ((nextptr = strtok(NULL, ",")) != NULL) {
|
|
while ((nextptr = strtok(NULL, ",")) != NULL) {
|
|
|
- get_intrange(nextptr, &val1, &val2);
|
|
|
|
|
|
|
+ if (!get_intrange(nextptr, &val1, &val2))
|
|
|
|
|
+ return "Invalid device number";
|
|
|
if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
|
|
if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
|
|
|
val1 > val2) {
|
|
val1 > val2) {
|
|
|
return "Invalid value passed to set devices";
|
|
return "Invalid value passed to set devices";
|