ed: Fix backslash expressions in RHS

By stripping backslashes this code caused a number of bugs.
'\<digit>' expressions caused literal <digit>s to be subbed-in,
'\&' was treated identically to '&', and other escaped characters
added garbage to the string.
This commit is contained in:
Wolfgang Corcoran-Mathe 2016-07-24 21:04:28 -04:00 committed by Laslo Hunhold
parent f5baf2630a
commit b7c73e2392

7
ed.c
View File

@ -900,13 +900,8 @@ getrhs(int delim)
free(s); free(s);
s = NULL; s = NULL;
siz = cap = 0; siz = cap = 0;
while ((c = input()) != '\n' && c != EOF && c != delim) { while ((c = input()) != '\n' && c != EOF && c != delim)
if (c == '\\') {
if ((c = input()) == '&' || isdigit(c))
s = addchar(c, s, &siz, &cap);
}
s = addchar(c, s, &siz, &cap); s = addchar(c, s, &siz, &cap);
}
s = addchar('\0', s, &siz, &cap); s = addchar('\0', s, &siz, &cap);
if (c == EOF) if (c == EOF)
error("invalid pattern delimiter"); error("invalid pattern delimiter");