ipl_tools: Allocate string buffer dynamically

Use util_asprintf() to allocate memory for the string buffers
dynamically and get rid of the following GCC8 compile warnings:

system.c: In function ‘print_fw_str’:
system.c:86:46: warning: ‘%s’ directive output may be truncated writing
up to 4095 bytes into a region of size 4082 [-Wformat-truncation=]
  snprintf(path, sizeof(path), "/sys/firmware/%s", file);
                                              ^~
system.c:98:19:
  read_fw_str(str, path, sizeof(str));
                   ~~~~
system.c:86:2: note: ‘snprintf’ output between 15 and 4110 bytes into a
destination of size 4096
  snprintf(path, sizeof(path), "/sys/firmware/%s", file);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cmd_chreipl.c: In function ‘set_reipl_type_helper’:
cmd_chreipl.c:316:19: warning: ‘%d’ directive writing between 1 and 11
bytes into a region of size between 0 and 4095 [-Wformat-overflow=]
  sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
                   ^~
cmd_chreipl.c:316:15: note: using the range [-2147483648, 2147483647]
for directive argument
  sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
               ^~~~~~~~~~
cmd_chreipl.c:316:15: note: using the range [-2147483648, 2147483647]
for directive argument
cmd_chreipl.c:316:2: note: ‘sprintf’ output between 5 and 4120 bytes
into a destination of size 4096
  sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-11-07 09:28:18 +01:00
parent 9f8d245f92
commit 6d382d30d9
3 changed files with 12 additions and 6 deletions

View File

@@ -4,6 +4,8 @@ libs = $(rootdir)/libutil/libutil.a
all: chreipl lsreipl chshut lsshut
libs = $(rootdir)/libutil/libutil.a
objects = main.o ccw.o fcp.o system.o shutdown.o \
cmd_lsshut.o cmd_chshut.o cmd_lsreipl.o cmd_chreipl.o proc.o

View File

@@ -303,19 +303,21 @@ static int set_reipl_type(const char *dev_name)
static int get_chreipl_helper_cmd(dev_t dev, char cmd[PATH_MAX])
{
char chreipl_helper[PATH_MAX];
char *chreipl_helper;
struct proc_dev_entry pde;
if (proc_dev_get_entry(dev, 1, &pde) != 0)
return -1;
snprintf(chreipl_helper, PATH_MAX,
"%s/%s.%s", TOOLS_LIBDIR, "chreipl_helper", pde.name);
util_asprintf(&chreipl_helper,
"%s/%s.%s", TOOLS_LIBDIR, "chreipl_helper", pde.name);
if (access(chreipl_helper, X_OK) != 0) {
proc_dev_free_entry(&pde);
free(chreipl_helper);
return -1;
}
sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
proc_dev_free_entry(&pde);
free(chreipl_helper);
return 0;
}

View File

@@ -9,6 +9,7 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#include "lib/util_libc.h"
#include "ipl_tools.h"
/*
@@ -81,10 +82,11 @@ void read_str(char *string, const char *path, size_t len)
*/
void read_fw_str(char *string, const char *file, size_t len)
{
char path[PATH_MAX];
char *path;
snprintf(path, sizeof(path), "/sys/firmware/%s", file);
return read_str(string, path, len);
util_asprintf(&path, "/sys/firmware/%s", file);
read_str(string, path, len);
free(path);
}
/*