diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2015-06-03 02:24:37 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2015-06-03 02:24:37 +0000 |
commit | 53f83ea972c751a287eed99558f9349e7238bc9f (patch) | |
tree | 98e3342250c23ad4626e591e9c43381815c024c7 /lib | |
parent | cf757a3268b6ecc9b77a4d2c3e3d4932433013a3 (diff) |
Do not assume that asprintf() clears the pointer on failure, which
is non-portable. Also add missing asprintf() return value checks.
OK deraadt@ guenther@ doug@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getgrouplist.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/getpwent.c | 12 | ||||
-rw-r--r-- | lib/libutil/pidfile.c | 5 |
3 files changed, 14 insertions, 9 deletions
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c index 651231124dd..79f6da75e8b 100644 --- a/lib/libc/gen/getgrouplist.c +++ b/lib/libc/gen/getgrouplist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getgrouplist.c,v 1.24 2014/09/15 06:15:48 guenther Exp $ */ +/* $OpenBSD: getgrouplist.c,v 1.25 2015/06/03 02:24:36 millert Exp $ */ /* * Copyright (c) 2008 Ingo Schwarze <schwarze@usta.de> * Copyright (c) 1991, 1993 @@ -204,8 +204,8 @@ getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt) if (getpwnam_r(uname, &pwstore, buf, sizeof buf, NULL) || (!__ypdomain && yp_get_default_domain(&__ypdomain))) goto out; - asprintf(&key, "unix.%u@%s", pwstore.pw_uid, __ypdomain); - if (key == NULL) + i = asprintf(&key, "unix.%u@%s", pwstore.pw_uid, __ypdomain); + if (i == -1) goto out; /* First scan the static netid file. */ diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 45f64fdf873..2d58e3f9bec 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpwent.c,v 1.53 2015/01/16 16:48:51 deraadt Exp $ */ +/* $OpenBSD: getpwent.c,v 1.54 2015/06/03 02:24:36 millert Exp $ */ /* * Copyright (c) 2008 Theo de Raadt * Copyright (c) 1988, 1993 @@ -542,11 +542,17 @@ __yppwlookup(int lookup, char *name, uid_t uid, struct passwd *pw, __ypproto_set(pw, yppbuf, *flagsp, &yp_pw_flags); if (!map) { if (lookup == LOOKUP_BYNAME) { + if ((name = strdup(name)) == NULL) { + pw = NULL; + goto done; + } map = PASSWD_BYNAME; - name = strdup(name); } else { + if (asprintf(&name, "%u", uid) == -1) { + pw = NULL; + goto done; + } map = PASSWD_BYUID; - asprintf(&name, "%u", uid); } } diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index 9bb68eb15b8..4c365d023ea 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pidfile.c,v 1.10 2014/06/30 00:26:22 deraadt Exp $ */ +/* $OpenBSD: pidfile.c,v 1.11 2015/06/03 02:24:36 millert Exp $ */ /* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */ /*- @@ -61,8 +61,7 @@ pidfile(const char *basename) } /* _PATH_VARRUN includes trailing / */ - (void) asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename); - if (pidfile_path == NULL) + if (asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename) == -1) return (-1); if ((f = fopen(pidfile_path, "w")) == NULL) { |