Date: Sun, 10 May 2015 10:02:09 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282718 - head/usr.sbin/pw Message-ID: <201505101002.t4AA29vb031421@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Sun May 10 10:02:09 2015 New Revision: 282718 URL: https://svnweb.freebsd.org/changeset/base/282718 Log: Use strndup(3) instead of malloc(3) + memcpy(3) Check the return of strndup Modified: head/usr.sbin/pw/pw_conf.c Modified: head/usr.sbin/pw/pw_conf.c ============================================================================== --- head/usr.sbin/pw/pw_conf.c Sun May 10 09:37:54 2015 (r282717) +++ head/usr.sbin/pw/pw_conf.c Sun May 10 10:02:09 2015 (r282718) @@ -34,6 +34,7 @@ static const char rcsid[] = #include <string.h> #include <ctype.h> #include <fcntl.h> +#include <err.h> #include "pw.h" @@ -211,15 +212,18 @@ boolean_str(int val) char * newstr(char const * p) { - char *q = NULL; + char *q; + size_t l; - if ((p = unquote(p)) != NULL) { - int l = strlen(p) + 1; + if ((p = unquote(p)) == NULL) + return (NULL); - if ((q = malloc(l)) != NULL) - memcpy(q, p, l); - } - return q; + l = strlen(p) + 1; + + if ((q = strndup(p, l)) == NULL) + err(1, "strndup()"); + + return (q); } struct userconf *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505101002.t4AA29vb031421>