diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-22 20:16:55 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-22 20:16:55 +0000 |
| commit | 0f293b96dc6effa127ec63e11dd16221f1329126 (patch) | |
| tree | a5b7873a5ece9bef8355da8d437cf53f952c66ca /libbb | |
| parent | 68a192c00799fd2097bab1aec594cd27203b1ec6 (diff) | |
| download | busybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.tar.gz busybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.tar.bz2 busybox-w32-0f293b96dc6effa127ec63e11dd16221f1329126.zip | |
fix all cases of strcpy on overlapping strings.
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/lineedit.c | 2 | ||||
| -rw-r--r-- | libbb/parse_config.c | 2 | ||||
| -rw-r--r-- | libbb/safe_strncpy.c | 9 |
3 files changed, 11 insertions, 2 deletions
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. */ | ||
| 21 | void FAST_FUNC overlapping_strcpy(char *dst, const char *src) | ||
| 22 | { | ||
| 23 | while ((*dst = *src) != '\0') { | ||
| 24 | dst++; | ||
| 25 | src++; | ||
| 26 | } | ||
| 27 | } | ||
