This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][Bug cli/14011] New: GDB uses strcpy() with undefined behaviour,causing bug in CLI cd_command().


> +2012-04-25  Fredrik Hederstierna  <fredrikh.hederstierna@securitas-direct.com>
> +
> +	* cli/cli-cmds.c (cd_command): Use memmove instead of strcpy because the
> +	strings overlap.
> +

Thanks for the patch. This looks good to me, except that there should
be a space before the opening parenthesis in function calls. You do
not seem to have a copyright assignment on file with the FSF, so we
will apply this patch under the "tiny patch" rule (change not legally
significant). Should you be interested in sending more changes in
the future, I recommend that you start the process now - contact me
off-list if you are interested and I will send you the form.

> Index: gdb/cli/cli-cmds.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
> retrieving revision 1.128
> diff -u -p -r1.128 cli-cmds.c
> --- gdb/cli/cli-cmds.c	1 Mar 2012 19:30:21 -0000	1.128
> +++ gdb/cli/cli-cmds.c	25 Apr 2012 09:22:37 -0000
> @@ -417,7 +417,7 @@ cd_command (char *dir, int from_tty)
>      {
>        if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.'
>  	  && (p[2] == 0 || IS_DIR_SEPARATOR (p[2])))
> -	strcpy (p, p + 2);
> +	memmove(p, p + 2, strlen(p + 2) + 1);
>        else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.'
>  	       && (p[3] == 0 || IS_DIR_SEPARATOR (p[3])))
>  	{
> @@ -436,7 +436,7 @@ cd_command (char *dir, int from_tty)
>  		++p;
>  	      else
>  		{
> -		  strcpy (q - 1, p + 3);
> +		  memmove(q - 1, p + 3, strlen(p + 3) + 1);
>  		  p = q - 1;
>  		}
>  	    }


-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]