Properly terminate the result string for intermediate results, to

allow the final strcpy() to start at the intended place.

Reported and tested by:	pgj
Pointy hat to:	kib
MFC after:	3 days
This commit is contained in:
Konstantin Belousov 2013-04-29 21:12:25 +00:00
parent 5c6fe3a917
commit 3c9cb0c6c9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=250075

View File

@ -784,7 +784,7 @@ origin_subst_one(char *real, const char *kw, const char *subst,
/*
* Now, execute the substitution loop.
*/
for (p = real, resp = res;;) {
for (p = real, resp = res, *resp = '\0';;) {
p1 = strstr(p, kw);
if (p1 != NULL) {
/* Copy the prefix before keyword. */
@ -793,6 +793,7 @@ origin_subst_one(char *real, const char *kw, const char *subst,
/* Keyword replacement. */
memcpy(resp, subst, subst_len);
resp += subst_len;
*resp = '\0';
p = p1 + kw_len;
} else
break;