lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 15 Nov 2021 08:38:33 +0000
From:   Avri Altman <Avri.Altman@....com>
To:     Bean Huo <huobean@...il.com>,
        "ulf.hansson@...aro.org" <ulf.hansson@...aro.org>,
        "adrian.hunter@...el.com" <adrian.hunter@...el.com>,
        "linux-mmc@...r.kernel.org" <linux-mmc@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     "beanhuo@...ron.com" <beanhuo@...ron.com>
Subject: RE: [PATCH v1 1/2] mmc-utils: Use memcpy instead of strncpy

Hi Bean,
> 
> The -Wstringop-truncation warning added in GCC 8.0:
>     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82944
> 
> If you use the GCC > v8.0, you probably will get this compilation error:
> 
> error: ‘__builtin_strncpy’ output may be truncated copying 8 bytes from a
> string of length 511 [-Werror=stringop-truncation]
> 
> Use memcpy instead of strncpy to avoid this compilation error.
> 
> Signed-off-by: Bean Huo <beanhuo@...ron.com>
Looking into the link above, it say that this warning:
"... is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL charcter from the source string."

As this is not the case here, I wouldn't worry about this warning.

Thanks,
Avri

> ---
>  mmc_cmds.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 205e6e5b89f9..ecbde3937c81 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -1835,7 +1835,8 @@ int do_read_extcsd(int nargs, char **argv)
> 
>         if (ext_csd_rev >= 7) {
>                  memset(lbuf, 0, sizeof(lbuf));
> -               strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
> +               memcpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
> +               lbuf[8] = '\0';
>                 printf("eMMC Firmware Version: %s\n", lbuf);
>                 printf("eMMC Life Time Estimation A
> [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
>                         ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
> --
> 2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ