diff options
author | 2015-05-10 10:02:09 +0000 | |
---|---|---|
committer | 2015-05-10 10:02:09 +0000 | |
commit | 23c65c2198c1b58184f7fafd8a70e8274fe1e91a (patch) | |
tree | 0361ca2ef3b98ec13635d3b0439945b90aa4e74c /pw/pw_conf.c | |
parent | c8d02e06b734db2f87942aa323b6004b52b8022f (diff) | |
download | pw-darwin-23c65c2198c1b58184f7fafd8a70e8274fe1e91a.tar.gz pw-darwin-23c65c2198c1b58184f7fafd8a70e8274fe1e91a.tar.zst pw-darwin-23c65c2198c1b58184f7fafd8a70e8274fe1e91a.zip |
Use strndup(3) instead of malloc(3) + memcpy(3)
Check the return of strndup
Diffstat (limited to 'pw/pw_conf.c')
-rw-r--r-- | pw/pw_conf.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/pw/pw_conf.c b/pw/pw_conf.c index 209982c..46474a1 100644 --- a/pw/pw_conf.c +++ b/pw/pw_conf.c @@ -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 * |