Actions
Bug #11510
closedstmsboot: stmsboot_util -D option validation is broken
Start date:
Due date:
% Done:
100%
Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:
Description
1. We allocate memory chunk with size MAXMODCONFNAME, but then we do copy data into it by strlen(optarg), replace bcopy by strlcpy.
2. strncmp() does compare n chars, that will allow to use names by prefix. Since with strlcpy we do have zero terminated strings, use normal strcmp.
3. the whole if strncmp() statement does not work:
the expression there should look like:
if (!((strncmp(drvlimit, "fp", 2) == 0) || (strncmp(drvlimit, "mpt", 3) == 0) || (strncmp(drvlimit, "mpt_sas", 7) == 0) || (strncmp(drvlimit, "pmcs", 4) == 0)))
Of course this one is a bit annoying to read, so we would like to reduce the !:
if (!(strncmp(drvlimit, "fp", 2) == 0) && !(strncmp(drvlimit, "mpt", 3) == 0) && !(strncmp(drvlimit, "mpt_sas", 7) == 0) && !(strncmp(drvlimit, "pmcs", 4) == 0))
And from above we already can see why the error did appear, nevertheless, to remove negation at all, the final if statement should be:
if ((strncmp(drvlimit, "fp", 2) != 0) && (strncmp(drvlimit, "mpt", 3) != 0) && (strncmp(drvlimit, "mpt_sas", 7) != 0) && (strncmp(drvlimit, "pmcs", 4) != 0))
Testing done:
Accepted, legal arguments: # /tmp/stmsboot_util -D fp -L stmsboot: MPXIO disabled Bad arguments: # /tmp/stmsboot_util -D fps -L usage: stmsboot_util -b | -m devname | -l <ctrl> | -L | [-g] | -n | -N | -i | -p devname More bad arguments: # /tmp/stmsboot_util -D asd -L usage: stmsboot_util -b | -m devname | -l <ctrl> | -L | [-g] | -n | -N | -i | -p devname
Actions