boundarydevices / imx_usb_loader

USB & UART loader for i.MX5/6/7/8 series
GNU Lesser General Public License v2.1
260 stars 158 forks source link

warning: the value of the size argument in 'strncat' is too large, might lead to a buffer overflow [-Wstrncat-size] #117

Closed saper closed 3 years ago

saper commented 3 years ago

clang 10.0.1 complains when building imx_sdp.c

cc -c imx_sdp.c -o imx_sdp.o -pipe -ggdb -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing  -DSYSCONFDIR='"/tmp/u-boot-imx-serial-loader-2017.01/etc"'
imx_sdp.c:144:22: warning: the value of the size argument in 'strncat' is too large, might lead to a
      buffer overflow [-Wstrncat-size]
        strncat(conf, &sep, sizeof(conf));
                            ^~~~~~~~~~~~
imx_sdp.c:144:22: note: change the argument to be the free space in the destination buffer minus the
      terminating null byte
        strncat(conf, &sep, sizeof(conf));
                            ^~~~~~~~~~~~
                            sizeof(conf) - strlen(conf) - 1
imx_sdp.c:145:27: warning: the value of the size argument in 'strncat' is too large, might lead to a
      buffer overflow [-Wstrncat-size]
        strncat(conf, conf_file, sizeof(conf));
                                 ^~~~~~~~~~~~
imx_sdp.c:145:27: note: change the argument to be the free space in the destination buffer minus the
      terminating null byte
        strncat(conf, conf_file, sizeof(conf));
                                 ^~~~~~~~~~~~
                                 sizeof(conf) - strlen(conf) - 1

Using

> clang -v
FreeBSD clang version 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd11.4
Thread model: posix
InstalledDir: /usr/bin
saper commented 3 years ago

(sorry, this was using the older code)