Re: [PATCH] kexec: Fix snprintf related compilation warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 23, 2020 at 04:42:37PM +0530, Bhupesh Sharma wrote:
> 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@xxxxxxxxxxxx>
> Cc: Eric Biederman <ebiederm@xxxxxxxxxxxx>
> Cc: kexec@xxxxxxxxxxxxxxxxxxx
> Signed-off-by: Bhupesh Sharma <bhsharma@xxxxxxxxxx>

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/kexec




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux