[PATCH] replace strcpy with strscpy for safe copy

Biancaa Ramesh posted 1 patch 3 months, 2 weeks ago
mm/shmem.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
[PATCH] replace strcpy with strscpy for safe copy
Posted by Biancaa Ramesh 3 months, 2 weeks ago
Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
---
 mm/shmem.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index b9081b817d28..6e5a5d6fc7e9 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -657,17 +657,18 @@ static int shmem_parse_huge(const char *str)
 	if (!str)
 		return -EINVAL;
 
-	if (!strcmp(str, "never"))
+	if (!strncmp(str,"never",strlen("never")+1)){
 		huge = SHMEM_HUGE_NEVER;
-	else if (!strcmp(str, "always"))
+	}
+	else if (!strncmp(str, "always", strlen("always") + 1))
 		huge = SHMEM_HUGE_ALWAYS;
-	else if (!strcmp(str, "within_size"))
+	else if (!strncmp(str, "within_size",strlen("Within_size")+1))
 		huge = SHMEM_HUGE_WITHIN_SIZE;
-	else if (!strcmp(str, "advise"))
+	else if (!strncmp(str,"advise",strlen("advise")+1))
 		huge = SHMEM_HUGE_ADVISE;
-	else if (!strcmp(str, "deny"))
+	else if (!strncmp(str,"deny",strlen("deny")+1))
 		huge = SHMEM_HUGE_DENY;
-	else if (!strcmp(str, "force"))
+	else if (!strncmp(str,"force",strlen("force")+1))
 		huge = SHMEM_HUGE_FORCE;
 	else
 		return -EINVAL;
@@ -5679,27 +5680,27 @@ static int __init setup_thp_shmem(char *str)
 				goto err;
 
 			nr = end - start + 1;
-			if (!strcmp(policy, "always")) {
+			if (!strncmp(policy,"always",strlen("always")+1)){
 				bitmap_set(&always, start, nr);
 				bitmap_clear(&inherit, start, nr);
 				bitmap_clear(&madvise, start, nr);
 				bitmap_clear(&within_size, start, nr);
-			} else if (!strcmp(policy, "advise")) {
+			} else if (!strncmp(policy,"advise",strlen("advise")+1)){
 				bitmap_set(&madvise, start, nr);
 				bitmap_clear(&inherit, start, nr);
 				bitmap_clear(&always, start, nr);
 				bitmap_clear(&within_size, start, nr);
-			} else if (!strcmp(policy, "inherit")) {
+			} else if (!strncmp(policy,"inherit",strlen("inherit")+1)){
 				bitmap_set(&inherit, start, nr);
 				bitmap_clear(&madvise, start, nr);
 				bitmap_clear(&always, start, nr);
 				bitmap_clear(&within_size, start, nr);
-			} else if (!strcmp(policy, "within_size")) {
+			} else if (!strncmp(policy,"within_size",strlen("within_size")+1)){
 				bitmap_set(&within_size, start, nr);
 				bitmap_clear(&inherit, start, nr);
 				bitmap_clear(&madvise, start, nr);
 				bitmap_clear(&always, start, nr);
-			} else if (!strcmp(policy, "never")) {
+			} else if (!strncmp(policy,"never",strlen("never")+1)){
 				bitmap_clear(&inherit, start, nr);
 				bitmap_clear(&madvise, start, nr);
 				bitmap_clear(&always, start, nr);
-- 
2.43.0


-- 
::DISCLAIMER::

---------------------------------------------------------------------
The 
contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only. Views or opinions, if any,
presented in 
this email are solely those of the author and may not
necessarily reflect 
the views or opinions of SSN Institutions (SSN) or its
affiliates. Any form 
of reproduction, dissemination, copying, disclosure,
modification, 
distribution and / or publication of this message without the
prior written 
consent of authorized representative of SSN is strictly
prohibited. If you 
have received this email in error please delete it and
notify the sender 
immediately.
---------------------------------------------------------------------
Header of this mail should have a valid DKIM signature for the domain 
ssn.edu.in <http://www.ssn.edu.in/>
Re: [PATCH] replace strcpy with strscpy for safe copy
Posted by David Laight 3 months, 2 weeks ago
On Tue, 21 Oct 2025 20:27:00 +0530
Biancaa Ramesh <biancaa2210329@ssn.edu.in> wrote:

A complete pile of bollocks....

> Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
> ---
>  mm/shmem.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index b9081b817d28..6e5a5d6fc7e9 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -657,17 +657,18 @@ static int shmem_parse_huge(const char *str)
>  	if (!str)
>  		return -EINVAL;
>  
> -	if (!strcmp(str, "never"))
> +	if (!strncmp(str,"never",strlen("never")+1)){
>  		huge = SHMEM_HUGE_NEVER;
> -	else if (!strcmp(str, "always"))
> +	}
> +	else if (!strncmp(str, "always", strlen("always") + 1))
>  		huge = SHMEM_HUGE_ALWAYS;
> -	else if (!strcmp(str, "within_size"))
> +	else if (!strncmp(str, "within_size",strlen("Within_size")+1))
>  		huge = SHMEM_HUGE_WITHIN_SIZE;
> -	else if (!strcmp(str, "advise"))
> +	else if (!strncmp(str,"advise",strlen("advise")+1))
>  		huge = SHMEM_HUGE_ADVISE;
> -	else if (!strcmp(str, "deny"))
> +	else if (!strncmp(str,"deny",strlen("deny")+1))
>  		huge = SHMEM_HUGE_DENY;
> -	else if (!strcmp(str, "force"))
> +	else if (!strncmp(str,"force",strlen("force")+1))
>  		huge = SHMEM_HUGE_FORCE;
>  	else
>  		return -EINVAL;
> @@ -5679,27 +5680,27 @@ static int __init setup_thp_shmem(char *str)
>  				goto err;
>  
>  			nr = end - start + 1;
> -			if (!strcmp(policy, "always")) {
> +			if (!strncmp(policy,"always",strlen("always")+1)){
>  				bitmap_set(&always, start, nr);
>  				bitmap_clear(&inherit, start, nr);
>  				bitmap_clear(&madvise, start, nr);
>  				bitmap_clear(&within_size, start, nr);
> -			} else if (!strcmp(policy, "advise")) {
> +			} else if (!strncmp(policy,"advise",strlen("advise")+1)){
>  				bitmap_set(&madvise, start, nr);
>  				bitmap_clear(&inherit, start, nr);
>  				bitmap_clear(&always, start, nr);
>  				bitmap_clear(&within_size, start, nr);
> -			} else if (!strcmp(policy, "inherit")) {
> +			} else if (!strncmp(policy,"inherit",strlen("inherit")+1)){
>  				bitmap_set(&inherit, start, nr);
>  				bitmap_clear(&madvise, start, nr);
>  				bitmap_clear(&always, start, nr);
>  				bitmap_clear(&within_size, start, nr);
> -			} else if (!strcmp(policy, "within_size")) {
> +			} else if (!strncmp(policy,"within_size",strlen("within_size")+1)){
>  				bitmap_set(&within_size, start, nr);
>  				bitmap_clear(&inherit, start, nr);
>  				bitmap_clear(&madvise, start, nr);
>  				bitmap_clear(&always, start, nr);
> -			} else if (!strcmp(policy, "never")) {
> +			} else if (!strncmp(policy,"never",strlen("never")+1)){
>  				bitmap_clear(&inherit, start, nr);
>  				bitmap_clear(&madvise, start, nr);
>  				bitmap_clear(&always, start, nr);