Hello,

Replace a malloc+strlcpy with strndup in cmdline_symset().
Parameter s is a "keyname=value" string and sym is the
"keyname" part.

If s is "=value", sym will be an empty string.
The patch doesn't change this behaviour although
it might be undesirable to call symset() with
an empty string. Possibly it could also return -1
if len is zero. Thoughts?

- Michael


Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/parse.y,v
retrieving revision 1.218
diff -u -p -u -r1.218 parse.y
--- parse.y     25 Aug 2018 19:05:23 -0000      1.218
+++ parse.y     1 Sep 2018 12:42:45 -0000
@@ -2129,11 +2129,10 @@ cmdline_symset(char *s)
        if ((val = strrchr(s, '=')) == NULL)
                return (-1);
 
-       len = strlen(s) - strlen(val) + 1;
-       if ((sym = malloc(len)) == NULL)
-               errx(1, "cmdline_symset: malloc");
-
-       (void)strlcpy(sym, s, len);
+       len = strlen(s) - strlen(val);
+       sym = strndup(s, len);
+       if (sym == NULL)
+               errx(1, "%s: strndup", __func__);
 
        ret = symset(sym, val + 1, 1);
        free(sym);

Reply via email to