zipl: use unsigned int for the iteration variable

This fixes the false positive

CC      zipl/src/misc.o
misc.c: In function ‘misc_temp_dev’:
misc.c:313:27: warning: ‘%04d’ directive writing between 4 and 11 bytes into a region of size 5 [-Wformat-overflow=]
    sprintf(filename, "zipl%04d", retry);
                           ^~~~
misc.c:313:22: note: directive argument in the range [-2147483648, 999]
    sprintf(filename, "zipl%04d", retry);
                      ^~~~~~~~~~
misc.c:313:4: note: ‘sprintf’ output between 9 and 16 bytes into a destination of size 9
    sprintf(filename, "zipl%04d", retry);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

While at it, add an assertion that protects against a format-overflow,
e.g. if TEMP_DEV_MAX_RETRIES changes.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2020-03-23 11:30:10 +01:00
committed by Jan Höppner
parent 4753340e79
commit c91d8bd5f9

View File

@@ -9,6 +9,7 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
@@ -296,7 +297,7 @@ misc_temp_dev(dev_t dev, int blockdev, char** devno)
char filename[] = "zipl0000";
mode_t mode;
unsigned int path;
int retry;
unsigned int retry;
int rc;
int fd;
@@ -310,7 +311,8 @@ misc_temp_dev(dev_t dev, int blockdev, char** devno)
if (pathname[path] == NULL)
continue;
for (retry=0; retry < TEMP_DEV_MAX_RETRIES; retry++) {
sprintf(filename, "zipl%04d", retry);
assert(retry < 10000);
sprintf(filename, "zipl%04u", retry);
result = misc_make_path(pathname[path], filename);
if (result == NULL)
return -1;