All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix strncpy() usage
@ 2021-11-16 10:51 Oleh Kravchenko
  2021-11-25 13:30 ` Ulf Hansson
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-16 10:51 UTC (permalink / raw)
  To: linux-mmc, Chris Ball, Ulf Hansson, Patchwork Bot; +Cc: Oleh Kravchenko

Manpage of strncpy() says:
If there is no null byte among the first n bytes of src,
the string placed in dest will not be null-terminated.

Put \0 to the end of the buffer to ensure that
the destination string is NULL-terminated.

This patch also fixes a compile error with a newer version of GCC.

Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
---
 mmc_cmds.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..016fe70 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1834,8 +1834,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);
+		strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], sizeof(lbuf) - 1);
+		lbuf[sizeof(lbuf) - 1] = 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.32.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-12-02 14:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 10:51 [PATCH] Fix strncpy() usage Oleh Kravchenko
2021-11-25 13:30 ` Ulf Hansson
2021-11-26 14:47 ` [PATCH v2] Replace strncpy() usage by printf() Oleh Kravchenko
2021-11-29 12:03   ` Ulf Hansson
2021-11-29 12:41 ` [PATCH v3] Use printf() to extract and print fw version Oleh Kravchenko
2021-11-29 15:05   ` [EXT] " Bean Huo (beanhuo)
2021-11-29 15:43     ` Oleh Kravchenko
2021-11-29 15:44 ` [PATCH v3] mmc-utils: " Oleh Kravchenko
2021-11-29 15:48 ` [PATCH v4] " Oleh Kravchenko
2021-11-30  7:42   ` Avri Altman
2021-11-30 12:07     ` Oleh Kravchenko
2021-11-30 12:14       ` Ulf Hansson
2021-11-30 14:25         ` Oleh Kravchenko
2021-11-30 14:27 ` [PATCH v5] " Oleh Kravchenko
2021-12-02 14:26   ` Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.