fix all cases of strcpy on overlapping strings.

This commit is contained in:
Denis Vlasenko
2008-07-22 20:16:55 +00:00
parent 68a192c007
commit 0f293b96dc
7 changed files with 15 additions and 5 deletions

View File

@@ -1552,7 +1552,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
vi_case(CTRL('U')|vbit:)
/* Control-U -- Clear line before cursor */
if (cursor) {
strcpy(command, command + cursor);
overlapping_strcpy(command, command + cursor);
command_len -= cursor;
redraw(cmdedit_y, command_len);
}

View File

@@ -161,7 +161,7 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
int n = strspn(line, delims);
if (n) {
ii -= n;
strcpy(line, line + n);
overlapping_strcpy(line, line + n);
}
// cut trailing
if (ii) {

View File

@@ -16,3 +16,12 @@ char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size)
dst[--size] = '\0';
return strncpy(dst, src, size);
}
/* Like strcpy but can copy overlapping strings. */
void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
{
while ((*dst = *src) != '\0') {
dst++;
src++;
}
}