sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 50ecbd43ad6d85f27eae5251bac7c72e37d35b78
parent df8529f0a1143b2972bcdb680c59bb8fb7426a36
Author: FRIGN <dev@frign.de>
Date:   Mon, 23 Mar 2015 22:31:36 +0100

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

Thanks emg for reporting this!

Diffstat:
Mexpr.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

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