This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Fix incorrect use of strcpy.
- From: Chris January <chris dot january at allinea dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 08 Mar 2012 14:21:24 +0000
- Subject: [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)