Can't use sizeof on malloc'ed array in expr(1)

Thanks emg for reporting this!
This commit is contained in:
FRIGN 2015-03-23 22:31:36 +01:00
parent df8529f0a1
commit 50ecbd43ad

8
expr.c
View File

@ -62,6 +62,7 @@ match(struct val *vstr, struct val *vregx, struct val *ret)
regex_t re; regex_t re;
regmatch_t matches[2]; regmatch_t matches[2];
long long d; long long d;
size_t anchlen;
char strbuf[maxdigits + 1], regxbuf[maxdigits + 1], char strbuf[maxdigits + 1], regxbuf[maxdigits + 1],
*s, *p, *anchreg, *str, *regx; *s, *p, *anchreg, *str, *regx;
const char *errstr; const char *errstr;
@ -81,9 +82,10 @@ match(struct val *vstr, struct val *vregx, struct val *ret)
} }
/* anchored regex */ /* anchored regex */
anchreg = emalloc(strlen(regx) + 2); anchlen = strlen(regx) + 1 + 1;
estrlcpy(anchreg, "^", sizeof(anchreg)); anchreg = emalloc(anchlen);
estrlcat(anchreg, regx, sizeof(anchreg)); estrlcpy(anchreg, "^", anchlen);
estrlcat(anchreg, regx, anchlen);
enregcomp(3, &re, anchreg, 0); enregcomp(3, &re, anchreg, 0);
free(anchreg); free(anchreg);