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]

[PATCH] Fix incorrect use of strcpy.


The strings passed to strcpy may not overlap, but &p and &p[len + 1]
clearly do. memmove allows overlapping memory area.

2012-03-08  Chris January  <chris.january@allinea.com>

        * source.c (add_path): Use memmove instead of strcpy because the
        strings overlap.
---
diff --git a/gdb/source.c b/gdb/source.c
index cfdf81b..7505309 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -588,7 +588,7 @@ add_path (char *dirname, char **which_path, int
parse_separators)
 		  p--;		/* Back over leading separator.  */
 		if (prefix > p - *which_path)
 		  goto skip_dup;	/* Same dir twice in one cmd.  */
-		strcpy (p, &p[len + 1]);	/* Copy from next \0 or  : */
+		memmove (p, &p[len + 1], strlen(&p[len + 1]) + 1);	/* Copy from next
\0 or  : */
 	      }
 	    p = strchr (p, DIRNAME_SEPARATOR);
 	    if (p != 0)




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