Commit 70cca822 authored by Bhupesh Sharma's avatar Bhupesh Sharma Committed by Simon Horman
Browse files

kexec: Fix snprintf related compilation warnings



This patch fixes the following snprintf related compilation warning
seen currently with gcc versions 7 and 8 when kexec is compiled with
-Wformat-truncation option:

    kexec/fs2dt.c:673:34: warning: ‘stdout-path’ directive output may be truncated writing 11 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
       snprintf(filename, MAXPATH, "%sstdout-path", pathname);
                                      ^~~~~~~~~~~
    kexec/fs2dt.c:673:3: note: ‘snprintf’ output between 12 and 1035 bytes into a destination of size 1024
       snprintf(filename, MAXPATH, "%sstdout-path", pathname);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    kexec/fs2dt.c:676:35: warning: ‘linux,stdout-path’ directive output may be truncated writing 17 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
        snprintf(filename, MAXPATH, "%slinux,stdout-path", pathname);
                                       ^~~~~~~~~~~~~~~~~
    kexec/fs2dt.c:676:4: note: ‘snprintf’ output between 18 and 1041 bytes into a destination of size 1024
        snprintf(filename, MAXPATH, "%slinux,stdout-path", pathname);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    kexec/firmware_memmap.c:132:35: warning: ‘%s’ directive output may be truncated writing 5 bytes into a region of size between 0 and 4095 [-Wformat-truncation=]
      snprintf(filename, PATH_MAX, "%s/%s", entry, "start");
                                       ^~          ~~~~~~~
    kexec/firmware_memmap.c:132:2: note: ‘snprintf’ output between 7 and 4102 bytes into a destination of size 4096
      snprintf(filename, PATH_MAX, "%s/%s", entry, "start");
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    kexec/firmware_memmap.c:142:35: warning: ‘%s’ directive output may be truncated writing 3 bytes into a region of size between 0 and 4095 [-Wformat-truncation=]
      snprintf(filename, PATH_MAX, "%s/%s", entry, "end");
                                       ^~          ~~~~~
    kexec/firmware_memmap.c:142:2: note: ‘snprintf’ output between 5 and 4100 bytes into a destination of size 4096
      snprintf(filename, PATH_MAX, "%s/%s", entry, "end");
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    kexec/firmware_memmap.c:152:35: warning: ‘%s’ directive output may be truncated writing 4 bytes into a region of size between 0 and 4095 [-Wformat-truncation=]
      snprintf(filename, PATH_MAX, "%s/%s", entry, "type");
                                       ^~          ~~~~~~
    kexec/firmware_memmap.c:152:2: note: ‘snprintf’ output between 6 and 4101 bytes into a destination of size 4096
      snprintf(filename, PATH_MAX, "%s/%s", entry, "type");
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since the simplest method to address the gcc warnings and possible
truncation would be to check the return value provided from snprintf
(well there are other methods like using 'asnprintf' or using
'open_memstream' function to create the FILE object, but these are more
intrusive), so this patch does the same.

Cc: Simon Horman <horms@verge.net.au>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: kexec@lists.infradead.org
Signed-off-by: default avatarBhupesh Sharma <bhsharma@redhat.com>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
parent 15fc8cb3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment