summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-22 20:16:55 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-22 20:16:55 +0000
commit0f293b96dc6effa127ec63e11dd16221f1329126 (patch)
treea5b7873a5ece9bef8355da8d437cf53f952c66ca
parent68a192c00799fd2097bab1aec594cd27203b1ec6 (diff)
downloadbusybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.tar.gz
busybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.tar.bz2
busybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.zip
fix all cases of strcpy on overlapping strings.
-rw-r--r--coreutils/printf.c2
-rw-r--r--editors/sed.c2
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/lineedit.c2
-rw-r--r--libbb/parse_config.c2
-rw-r--r--libbb/safe_strncpy.c9
-rw-r--r--procps/nmeter.c2
7 files changed, 15 insertions, 5 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 7f6235a87..72acbc751 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -289,7 +289,7 @@ static char **print_formatted(char *f, char **argv)
289 /* Remove size modifiers - "%Ld" would try to printf 289 /* Remove size modifiers - "%Ld" would try to printf
290 * long long, we pass long, and it spews garbage */ 290 * long long, we pass long, and it spews garbage */
291 if ((*f | 0x20) == 'l' || *f == 'h' || *f == 'z') { 291 if ((*f | 0x20) == 'l' || *f == 'h' || *f == 'z') {
292 strcpy(f, f + 1); 292 overlapping_strcpy(f, f + 1);
293 } 293 }
294//FIXME: actually, the same happens with bare "%d": 294//FIXME: actually, the same happens with bare "%d":
295//it printfs an int, but we pass long! 295//it printfs an int, but we pass long!
diff --git a/editors/sed.c b/editors/sed.c
index 496d3d22e..eb31f7d2e 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1219,7 +1219,7 @@ static void add_cmd_block(char *cmdstr)
1219 slashes++; 1219 slashes++;
1220 /* Odd number of preceding slashes - newline is escaped */ 1220 /* Odd number of preceding slashes - newline is escaped */
1221 if (slashes & 1) { 1221 if (slashes & 1) {
1222 strcpy(eol-1, eol); 1222 overlapping_strcpy(eol - 1, eol);
1223 eol = strchr(eol, '\n'); 1223 eol = strchr(eol, '\n');
1224 goto next; 1224 goto next;
1225 } 1225 }
diff --git a/include/libbb.h b/include/libbb.h
index 684e130c9..c0b731b36 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -540,6 +540,7 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
540 540
541char *xstrdup(const char *s) FAST_FUNC; 541char *xstrdup(const char *s) FAST_FUNC;
542char *xstrndup(const char *s, int n) FAST_FUNC; 542char *xstrndup(const char *s, int n) FAST_FUNC;
543void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
543char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; 544char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
544/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc. 545/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
545 * But potentially slow, don't use in one-billion-times loops */ 546 * But potentially slow, don't use in one-billion-times loops */
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 2e16e6a0a..032da24e7 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1552,7 +1552,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
1552 vi_case(CTRL('U')|vbit:) 1552 vi_case(CTRL('U')|vbit:)
1553 /* Control-U -- Clear line before cursor */ 1553 /* Control-U -- Clear line before cursor */
1554 if (cursor) { 1554 if (cursor) {
1555 strcpy(command, command + cursor); 1555 overlapping_strcpy(command, command + cursor);
1556 command_len -= cursor; 1556 command_len -= cursor;
1557 redraw(cmdedit_y, command_len); 1557 redraw(cmdedit_y, command_len);
1558 } 1558 }
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index 5109066d8..d1b29218b 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -161,7 +161,7 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
161 int n = strspn(line, delims); 161 int n = strspn(line, delims);
162 if (n) { 162 if (n) {
163 ii -= n; 163 ii -= n;
164 strcpy(line, line + n); 164 overlapping_strcpy(line, line + n);
165 } 165 }
166 // cut trailing 166 // cut trailing
167 if (ii) { 167 if (ii) {
diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c
index 649fa10cf..4acd9766b 100644
--- a/libbb/safe_strncpy.c
+++ b/libbb/safe_strncpy.c
@@ -16,3 +16,12 @@ char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size)
16 dst[--size] = '\0'; 16 dst[--size] = '\0';
17 return strncpy(dst, src, size); 17 return strncpy(dst, src, size);
18} 18}
19
20/* Like strcpy but can copy overlapping strings. */
21void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
22{
23 while ((*dst = *src) != '\0') {
24 dst++;
25 src++;
26 }
27}
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 8cff0b918..be039320b 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -800,7 +800,7 @@ int nmeter_main(int argc, char **argv)
800 if (!cur) 800 if (!cur)
801 break; 801 break;
802 if (cur[1] == '%') { // %% 802 if (cur[1] == '%') { // %%
803 strcpy(cur, cur+1); 803 overlapping_strcpy(cur, cur + 1);
804 cur++; 804 cur++;
805 goto again; 805 goto again;
806 } 806 }