commit 50ecbd43ad6d85f27eae5251bac7c72e37d35b78
Author: FRIGN <[email protected]>
Date:   Mon Mar 23 22:31:36 2015 +0100

    Can't use sizeof on malloc'ed array in expr(1)
    
    Thanks emg for reporting this!

diff --git a/expr.c b/expr.c
index 31b3726..b166a02 100644
--- 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);
 

Reply via email to