The buffer for a name to be copied into must also contain the
terminating 0 byte but strlen returns the length of the string without
counting that 0 byte. Adjust the length checks to take this into
account.
This issue found by Smatch.
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
goto out;
if (!strcmp(subcomm, "swap")) {
- if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > PART_NAME_LEN)) {
- printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN);
+ if ((strlen(name1) >= PART_NAME_LEN) || (strlen(name2) >= PART_NAME_LEN)) {
+ printf("Names longer than %d characters are truncated.\n",
+ PART_NAME_LEN - 1);
ret = -EINVAL;
goto out;
}
*first = *second;
*second = tmp_part;
} else { /* rename */
- if (strlen(name2) > PART_NAME_LEN) {
- printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN);
+ if (strlen(name2) >= PART_NAME_LEN) {
+ printf("Names longer than %d characters are truncated.\n",
+ PART_NAME_LEN - 1);
ret = -EINVAL;
goto out;
}