* [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
@ 2022-12-03 6:19 yang.yang29
2022-12-03 22:21 ` Luck, Tony
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: yang.yang29 @ 2022-12-03 6:19 UTC (permalink / raw)
To: tony.luck
Cc: bp, tglx, mingo, dave.hansen, x86, hpa, linux-edac, linux-kernel,
xu.panda, yang.yang29
From: Xu Panda <xu.panda@zte.com.cn>
The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.
Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
arch/x86/kernel/cpu/mce/dev-mcelog.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index 100fbeebdc72..a05ac0716ecf 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -105,8 +105,7 @@ static ssize_t set_trigger(struct device *s, struct device_attribute *attr,
{
char *p;
- strncpy(mce_helper, buf, sizeof(mce_helper));
- mce_helper[sizeof(mce_helper)-1] = 0;
+ strscpy(mce_helper, buf, sizeof(mce_helper));
p = strchr(mce_helper, '\n');
if (p)
--
2.15.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
2022-12-03 6:19 [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy() yang.yang29
@ 2022-12-03 22:21 ` Luck, Tony
2022-12-14 20:54 ` Ricardo Neri
2023-01-07 11:37 ` [tip: x86/platform] " tip-bot2 for Xu Panda
2 siblings, 0 replies; 6+ messages in thread
From: Luck, Tony @ 2022-12-03 22:21 UTC (permalink / raw)
To: yang.yang29
Cc: bp, tglx, mingo, dave.hansen, x86, hpa, linux-edac, linux-kernel,
xu.panda
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
Reviewed-by: Tony Luck <tony.luck@intel.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
2022-12-03 6:19 [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy() yang.yang29
2022-12-03 22:21 ` Luck, Tony
@ 2022-12-14 20:54 ` Ricardo Neri
2022-12-14 21:29 ` Luck, Tony
2023-01-07 11:37 ` [tip: x86/platform] " tip-bot2 for Xu Panda
2 siblings, 1 reply; 6+ messages in thread
From: Ricardo Neri @ 2022-12-14 20:54 UTC (permalink / raw)
To: yang.yang29
Cc: tony.luck, bp, tglx, mingo, dave.hansen, x86, hpa, linux-edac,
linux-kernel, xu.panda
On Sat, Dec 03, 2022 at 02:19:32PM +0800, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
It should read "NULL-terminated strings".
Thanks and BR,
Ricardo
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
2022-12-14 20:54 ` Ricardo Neri
@ 2022-12-14 21:29 ` Luck, Tony
2022-12-14 22:54 ` Ricardo Neri
0 siblings, 1 reply; 6+ messages in thread
From: Luck, Tony @ 2022-12-14 21:29 UTC (permalink / raw)
To: Ricardo Neri, yang.yang29
Cc: bp, tglx, mingo, dave.hansen, x86, hpa, linux-edac, linux-kernel,
xu.panda
>> The implementation of strscpy() is more robust and safer.
>> That's now the recommended way to copy NUL terminated strings.
>
> It should read "NULL-terminated strings".
Both "NUL-terminated" and "NULL-terminated" seem to be used in the kernel
source and commit comments. NULL is ahead 124:45 in the source, but it
is closer in the commit logs where the ratio is 129:76.
Single "L" NUL seems technically more accurate as the string terminator is
an ascii NUL character. From man 5 ascii the character name is NUL (though
the description says "null" to muddy the waters)
Oct Dec Hex Char
───────────────────────────────────────────
000 0 00 NUL '\0' (null character)
-Tony
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
2022-12-14 21:29 ` Luck, Tony
@ 2022-12-14 22:54 ` Ricardo Neri
0 siblings, 0 replies; 6+ messages in thread
From: Ricardo Neri @ 2022-12-14 22:54 UTC (permalink / raw)
To: Luck, Tony
Cc: yang.yang29, bp, tglx, mingo, dave.hansen, x86, hpa, linux-edac,
linux-kernel, xu.panda
On Wed, Dec 14, 2022 at 09:29:59PM +0000, Luck, Tony wrote:
> >> The implementation of strscpy() is more robust and safer.
> >> That's now the recommended way to copy NUL terminated strings.
> >
> > It should read "NULL-terminated strings".
>
> Both "NUL-terminated" and "NULL-terminated" seem to be used in the kernel
> source and commit comments. NULL is ahead 124:45 in the source, but it
> is closer in the commit logs where the ratio is 129:76.
>
> Single "L" NUL seems technically more accurate as the string terminator is
> an ascii NUL character. From man 5 ascii the character name is NUL (though
> the description says "null" to muddy the waters)
>
> Oct Dec Hex Char
> ───────────────────────────────────────────
> 000 0 00 NUL '\0' (null character)
Thanks for the analysis Tony. Indeed, I agree that "NUL-terminated" is
more accurate.
Thanks and BR,
Ricardo
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip: x86/platform] x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
2022-12-03 6:19 [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy() yang.yang29
2022-12-03 22:21 ` Luck, Tony
2022-12-14 20:54 ` Ricardo Neri
@ 2023-01-07 11:37 ` tip-bot2 for Xu Panda
2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Xu Panda @ 2023-01-07 11:37 UTC (permalink / raw)
To: linux-tip-commits
Cc: Xu Panda, Yang Yang, Ingo Molnar, Tony Luck, x86, linux-kernel
The following commit has been merged into the x86/platform branch of tip:
Commit-ID: 7ddf0050a21fdcc025c3cb1055fe3db60df1cd97
Gitweb: https://git.kernel.org/tip/7ddf0050a21fdcc025c3cb1055fe3db60df1cd97
Author: Xu Panda <xu.panda@zte.com.cn>
AuthorDate: Sat, 03 Dec 2022 14:19:32 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 07 Jan 2023 11:47:35 +01:00
x86/mce/dev-mcelog: use strscpy() to instead of strncpy()
The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.
Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/r/202212031419324523731@zte.com.cn
---
arch/x86/kernel/cpu/mce/dev-mcelog.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index 100fbee..a05ac07 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -105,8 +105,7 @@ static ssize_t set_trigger(struct device *s, struct device_attribute *attr,
{
char *p;
- strncpy(mce_helper, buf, sizeof(mce_helper));
- mce_helper[sizeof(mce_helper)-1] = 0;
+ strscpy(mce_helper, buf, sizeof(mce_helper));
p = strchr(mce_helper, '\n');
if (p)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-01-07 11:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-03 6:19 [PATCH linux-next] x86/mce/dev-mcelog: use strscpy() to instead of strncpy() yang.yang29
2022-12-03 22:21 ` Luck, Tony
2022-12-14 20:54 ` Ricardo Neri
2022-12-14 21:29 ` Luck, Tony
2022-12-14 22:54 ` Ricardo Neri
2023-01-07 11:37 ` [tip: x86/platform] " tip-bot2 for Xu Panda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®