x86/cpu/intel: replace deprecated strcpy with strscpy
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 x86/cpu/intel: replace deprecated strcpy with strscpy
strcpy is deprecated due to lack of bounds checking.
This patch replaces strcpy with strscpy, the recommended alternative for null terminated strings, to follow best practices.
--- arch/x86/kernel/cpu/intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/intel.c +1 -1
@@ -607,7 +607,7 @@ static void init_intel(struct cpuinfo_x86 *c) }if (p) -strcpy (c->x86_model_id, p); +strscpy (c->x86_model_id, p); }#endif
Signature · 1 line
2.48.1
H. Peter Anvin
reviewerQuoted 14 lines · Ruben Wauters
strcpy is deprecated due to lack of bounds checking.
This patch replaces strcpy with strscpy, the recommended alternative for null terminated strings, to follow best practices.Signed-off-by Ruben Wauters <[email protected]>---
arch/x86/kernel/cpu/intel.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/intel.c +0
-0
arch/x86/kernel/cpu/intel.c static void init_intel(struct cpuinfo_x86 *c) · line 613
Quoted 8 lines
arch/x86/kernel/cpu/intel.c +1
-1@@ -607,7 +607,7 @@ static void init_intel(struct cpuinfo_x86 *c) }if (p) -strcpy (c->x86_model_id, p); +strscpy (c->x86_model_id, p); }#endif
strscpy() needs a buffer length; this patch wouldn't even compile!
Not to mention that the string in question is generated in such a way that cannot be unterminated.
Quoted 20 lines · H. Peter Anvin
Quoted 18 lines · Ruben Wauters
strcpy is deprecated due to lack of bounds checking. This patch replaces strcpy with strscpy, the recommended alternative for
null terminated strings, to follow best practices.Signed-off-by Ruben Wauters <[email protected]>---
arch/x86/kernel/cpu/intel.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/intel.c +0
-0@@ -607,7 +607,7 @@ static void init_intel(struct cpuinfo_x86 *c) }
Quoted 8 lines
arch/x86/kernel/cpu/intel.c static void init_intel(struct cpuinfo_x86 *c) · line 613
Quoted 6 lines
arch/x86/kernel/cpu/intel.c +1
-1if (p) - strcpy(c->x86_model_id, p); + strscpy(c->x86_model_id, p); }#endif
strscpy()needs a buffer length; this patch wouldn't even compile!
Hi, this is incorrect, strscpy is defined in string.h as
#define strscpy(dst, src, ...) \ CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src,
__VA_ARGS__)
the third parameter is optional, and it works perfectly fine with two parameters. I have compiled it, and there are no errors.
Quoted 2 lines
Not to mention that the string in question is generated in such a way that cannot be unterminated.
I'm not entirely sure what you mean here? The assignments above are null terminated strings, which the two parameter version works fine with.
Quoted 38 lines · Ruben Wauters
Quoted 20 lines · H. Peter Anvin
Quoted 18 lines · Ruben Wauters
strcpy is deprecated due to lack of bounds checking. This patch replaces strcpy with strscpy, the recommended alternative for
null terminated strings, to follow best practices.Signed-off-by Ruben Wauters <[email protected]>---
arch/x86/kernel/cpu/intel.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/intel.c +0
-0@@ -607,7 +607,7 @@ static void init_intel(struct cpuinfo_x86 *c) }Quoted 8 lines
arch/x86/kernel/cpu/intel.c static void init_intel(struct cpuinfo_x86 *c) · line 613
Quoted 6 lines
arch/x86/kernel/cpu/intel.c +1
-1if (p) - strcpy(c->x86_model_id, p); + strscpy(c->x86_model_id, p); }#endif
strscpy()needs a buffer length; this patch wouldn't even compile!Hi, this is incorrect, strscpy is defined in
string.has#define strscpy(dst, src, ...) \ CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src,
__VA_ARGS__)the third parameter is optional, and it works perfectly fine with two parameters. I have compiled it, and there are no errors.
Quoted 7 lines
Quoted 3 lines
Not to mention that the string in question is generated in such a way
that cannot be unterminated.I'm not entirely sure what you mean here? The assignments above are null terminated strings, which the two parameter version works fine with.
Hello
Just wanted to check that everything was ok with this patch, and that any concerns were addressed or explained. Please do let me know if there is anything I need to do or change to get this patch applied.
Ruben Wauters
H. Peter Anvin
reviewerQuoted 47 lines · Ruben Wauters
Quoted 38 lines · Ruben Wauters
Quoted 20 lines · H. Peter Anvin
Quoted 18 lines · Ruben Wauters
strcpy is deprecated due to lack of bounds checking. This patch replaces strcpy with strscpy, the recommended alternative for
null terminated strings, to follow best practices.Signed-off-by Ruben Wauters <[email protected]>---
arch/x86/kernel/cpu/intel.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/intel.c +0
-0@@ -607,7 +607,7 @@ static void init_intel(struct cpuinfo_x86 *c) }Quoted 8 lines
arch/x86/kernel/cpu/intel.c static void init_intel(struct cpuinfo_x86 *c) · line 613
Quoted 6 lines
arch/x86/kernel/cpu/intel.c +1
-1if (p) - strcpy(c->x86_model_id, p); + strscpy(c->x86_model_id, p); }#endif
strscpy()needs a buffer length; this patch wouldn't even compile!Hi, this is incorrect, strscpy is defined in
string.has#define strscpy(dst, src, ...) \ CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src,
__VA_ARGS__)the third parameter is optional, and it works perfectly fine with two parameters. I have compiled it, and there are no errors.
Quoted 7 lines
Quoted 3 lines
Not to mention that the string in question is generated in such a way
that cannot be unterminated.I'm not entirely sure what you mean here? The assignments above are null terminated strings, which the two parameter version works fine with.
Quoted 8 lines
Hello
Just wanted to check that everything was ok with this patch, and that any concerns were addressed or explained. Please do let me know if there is anything I need to do or change to get this patch applied.
Ruben Wauters
Yes, I stand corrected.
I still think it is superfluous (or arguably a memcpy would be better, since this is a fixed length) but it doesn't hurt enything.