mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user