* [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
* Re: [PATCH] Fix strncpy() usage
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
` (4 subsequent siblings)
5 siblings, 0 replies; 15+ messages in thread
From: Ulf Hansson @ 2021-11-25 13:30 UTC (permalink / raw)
To: Oleh Kravchenko, Avri Altman, Bean Huo (beanhuo); +Cc: linux-mmc
+ Avri, Bean
On Tue, 16 Nov 2021 at 11:51, Oleh Kravchenko <oleg@kaa.org.ua> wrote:
>
> 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);
This may look better, but is actually making it worse. lbuf is 10
bytes long, while the ext_csd is 8 bytes.
> + 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
>
Kind regards
Uffe
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] Replace strncpy() usage by printf()
2021-11-16 10:51 [PATCH] Fix strncpy() usage Oleh Kravchenko
2021-11-25 13:30 ` Ulf Hansson
@ 2021-11-26 14:47 ` 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
` (3 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-26 14:47 UTC (permalink / raw)
To: linux-mmc, chrisball, 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 | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..753fcd9 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
__u32 regl;
int fd, ret;
char *device;
- char lbuf[10];
const char *str;
if (nargs != 2) {
@@ -1834,9 +1833,7 @@ 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);
- printf("eMMC Firmware Version: %s\n", lbuf);
+ printf("eMMC Firmware Version: %.*s\n", 8, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
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]);
printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] Replace strncpy() usage by printf()
2021-11-26 14:47 ` [PATCH v2] Replace strncpy() usage by printf() Oleh Kravchenko
@ 2021-11-29 12:03 ` Ulf Hansson
0 siblings, 0 replies; 15+ messages in thread
From: Ulf Hansson @ 2021-11-29 12:03 UTC (permalink / raw)
To: Oleh Kravchenko; +Cc: linux-mmc, chrisball, patchwork-bot, Avri Altman
+ Avri
On Fri, 26 Nov 2021 at 15:48, Oleh Kravchenko <oleg@kaa.org.ua> wrote:
>
> 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.
Please update the commit message to reflect what the patch really
does, as the above is no longer correct.
>
> This patch also fixes a compile error with a newer version of GCC.
>
> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
At next submission, please also add Avri Altman <avri.altman@wdc.com>,
who co-maintains the mmc-utils.
> ---
> mmc_cmds.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 73bd32a..753fcd9 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
> __u32 regl;
> int fd, ret;
> char *device;
> - char lbuf[10];
> const char *str;
>
> if (nargs != 2) {
> @@ -1834,9 +1833,7 @@ 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);
> - printf("eMMC Firmware Version: %s\n", lbuf);
> + printf("eMMC Firmware Version: %.*s\n", 8, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
This looks good to me. However, I suggest you skip the dynamic length
format. Just use %.8s.
> 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]);
> printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
> --
> 2.32.0
>
Kind regards
Uffe
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] Use printf() to extract and print fw version
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:41 ` Oleh Kravchenko
2021-11-29 15:05 ` [EXT] " Bean Huo (beanhuo)
2021-11-29 15:44 ` [PATCH v3] mmc-utils: " Oleh Kravchenko
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-29 12:41 UTC (permalink / raw)
To: Avri Altman, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
Cc: Oleh Kravchenko
This patch also fixes a compile error with a newer version of GCC:
error: '__builtin_strncpy' output may be truncated copying 8 bytes from
a string of length 511 [-Werror=stringop-truncation]
Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
---
mmc_cmds.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..e07ec94 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
__u32 regl;
int fd, ret;
char *device;
- char lbuf[10];
const char *str;
if (nargs != 2) {
@@ -1834,9 +1833,7 @@ 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);
- printf("eMMC Firmware Version: %s\n", lbuf);
+ printf("eMMC Firmware Version: %.8s\n", (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
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]);
printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [EXT] [PATCH v3] Use printf() to extract and print fw version
2021-11-29 12:41 ` [PATCH v3] Use printf() to extract and print fw version Oleh Kravchenko
@ 2021-11-29 15:05 ` Bean Huo (beanhuo)
2021-11-29 15:43 ` Oleh Kravchenko
0 siblings, 1 reply; 15+ messages in thread
From: Bean Huo (beanhuo) @ 2021-11-29 15:05 UTC (permalink / raw)
To: Oleh Kravchenko, Avri Altman, Chris Ball, Ulf Hansson, linux-mmc,
patchwork-bot
Micron Confidential
> Cc: Oleh Kravchenko <oleg@kaa.org.ua>
> Subject: [EXT] [PATCH v3] Use printf() to extract and print fw version
>
> CAUTION: EXTERNAL EMAIL. Do not click links or open attachments unless you
> recognize the sender and were expecting this message.
>
>
> This patch also fixes a compile error with a newer version of GCC:
> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a string
> of length 511 [-Werror=stringop-truncation]
>
> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Hi Oleh,
It is better to add the prefix "mmc-utils:" in the Commit subject to distinguish it from Linux kernel changes
Reviewed-by: Bean Huo <beanhuo@micron.com>
Micron Confidential
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [EXT] [PATCH v3] Use printf() to extract and print fw version
2021-11-29 15:05 ` [EXT] " Bean Huo (beanhuo)
@ 2021-11-29 15:43 ` Oleh Kravchenko
0 siblings, 0 replies; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-29 15:43 UTC (permalink / raw)
To: Bean Huo (beanhuo),
Avri Altman, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
29.11.21 17:05, Bean Huo (beanhuo) пише:
> Micron Confidential
>
>> Cc: Oleh Kravchenko <oleg@kaa.org.ua>
>> Subject: [EXT] [PATCH v3] Use printf() to extract and print fw version
>>
>> CAUTION: EXTERNAL EMAIL. Do not click links or open attachments unless you
>> recognize the sender and were expecting this message.
>>
>>
>> This patch also fixes a compile error with a newer version of GCC:
>> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a string
>> of length 511 [-Werror=stringop-truncation]
>>
>> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
> Hi Oleh,
>
> It is better to add the prefix "mmc-utils:" in the Commit subject to distinguish it from Linux kernel changes
Will do it.
> Reviewed-by: Bean Huo <beanhuo@micron.com>
Thanks!
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] mmc-utils: Use printf() to extract and print fw version
2021-11-16 10:51 [PATCH] Fix strncpy() usage Oleh Kravchenko
` (2 preceding siblings ...)
2021-11-29 12:41 ` [PATCH v3] Use printf() to extract and print fw version Oleh Kravchenko
@ 2021-11-29 15:44 ` Oleh Kravchenko
2021-11-29 15:48 ` [PATCH v4] " Oleh Kravchenko
2021-11-30 14:27 ` [PATCH v5] " Oleh Kravchenko
5 siblings, 0 replies; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-29 15:44 UTC (permalink / raw)
To: Avri Altman, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
Cc: Oleh Kravchenko, Bean Huo
This patch also fixes a compile error with a newer version of GCC:
error: '__builtin_strncpy' output may be truncated copying 8 bytes from
a string of length 511 [-Werror=stringop-truncation]
Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Reviewed-by: Bean Huo <beanhuo@micron.com>
---
mmc_cmds.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Update commit message.
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..e07ec94 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
__u32 regl;
int fd, ret;
char *device;
- char lbuf[10];
const char *str;
if (nargs != 2) {
@@ -1834,9 +1833,7 @@ 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);
- printf("eMMC Firmware Version: %s\n", lbuf);
+ printf("eMMC Firmware Version: %.8s\n", (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
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]);
printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4] mmc-utils: Use printf() to extract and print fw version
2021-11-16 10:51 [PATCH] Fix strncpy() usage Oleh Kravchenko
` (3 preceding siblings ...)
2021-11-29 15:44 ` [PATCH v3] mmc-utils: " Oleh Kravchenko
@ 2021-11-29 15:48 ` Oleh Kravchenko
2021-11-30 7:42 ` Avri Altman
2021-11-30 14:27 ` [PATCH v5] " Oleh Kravchenko
5 siblings, 1 reply; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-29 15:48 UTC (permalink / raw)
To: Avri Altman, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
Cc: Oleh Kravchenko, Bean Huo
This patch also fixes a compile error with a newer version of GCC:
error: '__builtin_strncpy' output may be truncated copying 8 bytes from
a string of length 511 [-Werror=stringop-truncation]
Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Reviewed-by: Bean Huo <beanhuo@micron.com>
---
mmc_cmds.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
PATCH v4
Update commit message.
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..e07ec94 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
__u32 regl;
int fd, ret;
char *device;
- char lbuf[10];
const char *str;
if (nargs != 2) {
@@ -1834,9 +1833,7 @@ 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);
- printf("eMMC Firmware Version: %s\n", lbuf);
+ printf("eMMC Firmware Version: %.8s\n", (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
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]);
printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [PATCH v4] mmc-utils: Use printf() to extract and print fw version
2021-11-29 15:48 ` [PATCH v4] " Oleh Kravchenko
@ 2021-11-30 7:42 ` Avri Altman
2021-11-30 12:07 ` Oleh Kravchenko
0 siblings, 1 reply; 15+ messages in thread
From: Avri Altman @ 2021-11-30 7:42 UTC (permalink / raw)
To: Oleh Kravchenko, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
Cc: Bean Huo
Hi,
>
> This patch also fixes a compile error with a newer version of GCC:
> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a
> string of length 511 [-Werror=stringop-truncation]
You are reverting commit 0eea71e4f2 (mmc-utils: Fix for Firmware Version string printing).
Please use git revert and add an explanation in your commit log.
You might also would like to take a look at the correspondence concerning a different approach to the same issue here - https://lore.kernel.org/lkml/20211114204331.39555-2-huobean@gmail.com/
Thanks,
Avri
>
> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
> Reviewed-by: Bean Huo <beanhuo@micron.com>
> ---
> mmc_cmds.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> PATCH v4
> Update commit message.
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 73bd32a..e07ec94 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
> __u32 regl;
> int fd, ret;
> char *device;
> - char lbuf[10];
> const char *str;
>
> if (nargs != 2) {
> @@ -1834,9 +1833,7 @@ 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);
> - printf("eMMC Firmware Version: %s\n", lbuf);
> + printf("eMMC Firmware Version: %.8s\n",
> + (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
> 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]);
> printf("eMMC Life Time Estimation B
> [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
> --
> 2.32.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4] mmc-utils: Use printf() to extract and print fw version
2021-11-30 7:42 ` Avri Altman
@ 2021-11-30 12:07 ` Oleh Kravchenko
2021-11-30 12:14 ` Ulf Hansson
0 siblings, 1 reply; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-30 12:07 UTC (permalink / raw)
To: Avri Altman; +Cc: Bean Huo, Chris Ball, Ulf Hansson, linux-mmc
Hello Avri!
30.11.21 09:42, Avri Altman пише:
> Hi,
>> This patch also fixes a compile error with a newer version of GCC:
>> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a
>> string of length 511 [-Werror=stringop-truncation]
> You are reverting commit 0eea71e4f2 (mmc-utils: Fix for Firmware Version string printing).
> Please use git revert and add an explanation in your commit log.
I'm not reverting this commit.
It's similar but not.
>
> You might also would like to take a look at the correspondence concerning a different approach to the same issue here - https://lore.kernel.org/lkml/20211114204331.39555-2-huobean@gmail.com/
Thank you.
I didn't know that.
>
> Thanks,
> Avri
>
>> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
>> Reviewed-by: Bean Huo <beanhuo@micron.com>
>> ---
>> mmc_cmds.c | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> PATCH v4
>> Update commit message.
>>
>> diff --git a/mmc_cmds.c b/mmc_cmds.c
>> index 73bd32a..e07ec94 100644
>> --- a/mmc_cmds.c
>> +++ b/mmc_cmds.c
>> @@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
>> __u32 regl;
>> int fd, ret;
>> char *device;
>> - char lbuf[10];
>> const char *str;
>>
>> if (nargs != 2) {
>> @@ -1834,9 +1833,7 @@ 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);
>> - printf("eMMC Firmware Version: %s\n", lbuf);
>> + printf("eMMC Firmware Version: %.8s\n",
>> + (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
>> 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]);
>> printf("eMMC Life Time Estimation B
>> [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
>> --
>> 2.32.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4] mmc-utils: Use printf() to extract and print fw version
2021-11-30 12:07 ` Oleh Kravchenko
@ 2021-11-30 12:14 ` Ulf Hansson
2021-11-30 14:25 ` Oleh Kravchenko
0 siblings, 1 reply; 15+ messages in thread
From: Ulf Hansson @ 2021-11-30 12:14 UTC (permalink / raw)
To: Oleh Kravchenko; +Cc: Avri Altman, Bean Huo, Chris Ball, linux-mmc
On Tue, 30 Nov 2021 at 13:07, Oleh Kravchenko <oleg@kaa.org.ua> wrote:
>
> Hello Avri!
>
> 30.11.21 09:42, Avri Altman пише:
> > Hi,
> >> This patch also fixes a compile error with a newer version of GCC:
> >> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a
> >> string of length 511 [-Werror=stringop-truncation]
> > You are reverting commit 0eea71e4f2 (mmc-utils: Fix for Firmware Version string printing).
> > Please use git revert and add an explanation in your commit log.
>
> I'm not reverting this commit.
> It's similar but not.
Right, this time we limit the print to 8 chars, which avoids garbage
from a non-NULL terminated string.
Perhaps we should add (similar to what we do for kernel commits):
Fixes: 0eea71e4f22a ("mmc-utils: Fix for Firmware Version string printing")
[...]
Kind regards
Uffe
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4] mmc-utils: Use printf() to extract and print fw version
2021-11-30 12:14 ` Ulf Hansson
@ 2021-11-30 14:25 ` Oleh Kravchenko
0 siblings, 0 replies; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-30 14:25 UTC (permalink / raw)
To: Ulf Hansson; +Cc: Avri Altman, Bean Huo, Chris Ball, linux-mmc
Hello Ulf,
30.11.21 14:14, Ulf Hansson пише:
> On Tue, 30 Nov 2021 at 13:07, Oleh Kravchenko <oleg@kaa.org.ua> wrote:
>> Hello Avri!
>>
>> 30.11.21 09:42, Avri Altman пише:
>>> Hi,
>>>> This patch also fixes a compile error with a newer version of GCC:
>>>> error: '__builtin_strncpy' output may be truncated copying 8 bytes from a
>>>> string of length 511 [-Werror=stringop-truncation]
>>> You are reverting commit 0eea71e4f2 (mmc-utils: Fix for Firmware Version string printing).
>>> Please use git revert and add an explanation in your commit log.
>> I'm not reverting this commit.
>> It's similar but not.
> Right, this time we limit the print to 8 chars, which avoids garbage
> from a non-NULL terminated string.
>
> Perhaps we should add (similar to what we do for kernel commits):
> Fixes: 0eea71e4f22a ("mmc-utils: Fix for Firmware Version string printing")
Good point!
>
> [...]
>
> Kind regards
> Uffe
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v5] mmc-utils: Use printf() to extract and print fw version
2021-11-16 10:51 [PATCH] Fix strncpy() usage Oleh Kravchenko
` (4 preceding siblings ...)
2021-11-29 15:48 ` [PATCH v4] " Oleh Kravchenko
@ 2021-11-30 14:27 ` Oleh Kravchenko
2021-12-02 14:26 ` Ulf Hansson
5 siblings, 1 reply; 15+ messages in thread
From: Oleh Kravchenko @ 2021-11-30 14:27 UTC (permalink / raw)
To: Avri Altman, Chris Ball, Ulf Hansson, linux-mmc, patchwork-bot
Cc: Oleh Kravchenko, Bean Huo
This patch also fixes a compile error with a newer version of GCC:
error: '__builtin_strncpy' output may be truncated copying 8 bytes from
a string of length 511 [-Werror=stringop-truncation]
Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Fixes: 0eea71e4f22a (mmc-utils: Fix for Firmware Version string printing)
---
mmc_cmds.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
PATCH v5
Updating commit message.
Adding Fixes: 0eea71e4f22a
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 73bd32a..e07ec94 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
__u32 regl;
int fd, ret;
char *device;
- char lbuf[10];
const char *str;
if (nargs != 2) {
@@ -1834,9 +1833,7 @@ 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);
- printf("eMMC Firmware Version: %s\n", lbuf);
+ printf("eMMC Firmware Version: %.8s\n", (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
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]);
printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
--
2.32.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v5] mmc-utils: Use printf() to extract and print fw version
2021-11-30 14:27 ` [PATCH v5] " Oleh Kravchenko
@ 2021-12-02 14:26 ` Ulf Hansson
0 siblings, 0 replies; 15+ messages in thread
From: Ulf Hansson @ 2021-12-02 14:26 UTC (permalink / raw)
To: Oleh Kravchenko
Cc: Avri Altman, Chris Ball, linux-mmc, patchwork-bot, Bean Huo
On Tue, 30 Nov 2021 at 15:27, Oleh Kravchenko <oleg@kaa.org.ua> wrote:
>
> This patch also fixes a compile error with a newer version of GCC:
> error: '__builtin_strncpy' output may be truncated copying 8 bytes from
> a string of length 511 [-Werror=stringop-truncation]
>
> Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
> Reviewed-by: Bean Huo <beanhuo@micron.com>
> Fixes: 0eea71e4f22a (mmc-utils: Fix for Firmware Version string printing)
Applied to git.kernel.org/pub/scm/utils/mmc/mmc-utils.git master, thanks!
Kind regards
Uffe
> ---
> mmc_cmds.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> PATCH v5
> Updating commit message.
> Adding Fixes: 0eea71e4f22a
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 73bd32a..e07ec94 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -1392,7 +1392,6 @@ int do_read_extcsd(int nargs, char **argv)
> __u32 regl;
> int fd, ret;
> char *device;
> - char lbuf[10];
> const char *str;
>
> if (nargs != 2) {
> @@ -1834,9 +1833,7 @@ 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);
> - printf("eMMC Firmware Version: %s\n", lbuf);
> + printf("eMMC Firmware Version: %.8s\n", (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
> 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]);
> printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
> --
> 2.32.0
>
^ permalink raw reply [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.