diff mbox

utilities: kernelscan: use memmove instead of strcpy

Message ID 1405428862-23307-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King July 15, 2014, 12:54 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

better to use memmove rather than strcpy; Coverity Scan reports
that there is a potential overlap with the underlying memory copy
so use memmove which has the smarts to do this correctly.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/utilities/kernelscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Keng-Yu Lin July 22, 2014, 8:56 a.m. UTC | #1
On Tue, Jul 15, 2014 at 8:54 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> better to use memmove rather than strcpy; Coverity Scan reports
> that there is a potential overlap with the underlying memory copy
> so use memmove which has the smarts to do this correctly.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/utilities/kernelscan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
> index 1b793bb..78c70d5 100644
> --- a/src/utilities/kernelscan.c
> +++ b/src/utilities/kernelscan.c
> @@ -741,7 +741,7 @@ static void literal_strip_quotes(token *t)
>
>         t->token[len-1] = 0;
>
> -       strcpy(t->token, t->token + 1);
> +       memmove(t->token, t->token + 1, len - 1);
>  }
>
>  /*
> --
> 2.0.1
>
>

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung July 24, 2014, 6:48 a.m. UTC | #2
On 07/15/2014 08:54 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> better to use memmove rather than strcpy; Coverity Scan reports
> that there is a potential overlap with the underlying memory copy
> so use memmove which has the smarts to do this correctly.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/utilities/kernelscan.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
> index 1b793bb..78c70d5 100644
> --- a/src/utilities/kernelscan.c
> +++ b/src/utilities/kernelscan.c
> @@ -741,7 +741,7 @@ static void literal_strip_quotes(token *t)
>
>   	t->token[len-1] = 0;
>
> -	strcpy(t->token, t->token + 1);
> +	memmove(t->token, t->token + 1, len - 1);
>   }
>
>   /*
>


Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
index 1b793bb..78c70d5 100644
--- a/src/utilities/kernelscan.c
+++ b/src/utilities/kernelscan.c
@@ -741,7 +741,7 @@  static void literal_strip_quotes(token *t)
 
 	t->token[len-1] = 0;
 
-	strcpy(t->token, t->token + 1);
+	memmove(t->token, t->token + 1, len - 1);
 }
 
 /*