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 /libexec/ld.so/ldconfig | |
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 'libexec/ld.so/ldconfig')
-rw-r--r-- | libexec/ld.so/ldconfig/prebind.c | 13 | ||||
-rw-r--r-- | libexec/ld.so/ldconfig/prebind_delete.c | 15 |
2 files changed, 22 insertions, 6 deletions
diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c index cb7e4535d49..785929b7663 100644 --- a/libexec/ld.so/ldconfig/prebind.c +++ b/libexec/ld.so/ldconfig/prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind.c,v 1.28 2015/01/16 16:18:07 deraadt Exp $ */ +/* $OpenBSD: prebind.c,v 1.29 2015/06/03 02:24:36 millert Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -268,14 +268,20 @@ load_dir(char *name) * NFS will return unknown, since load_file * does stat the file, this just */ - asprintf(&buf, "%s/%s", name, dp->d_name); + if (asprintf(&buf, "%s/%s", name, dp->d_name) == -1) { + warn("asprintf"); + goto done; + } lstat(buf, &sb); if (sb.st_mode == S_IFREG) load_exe(buf); free(buf); break; case DT_REG: - asprintf(&buf, "%s/%s", name, dp->d_name); + if (asprintf(&buf, "%s/%s", name, dp->d_name) == -1) { + warn("asprintf"); + goto done; + } load_exe(buf); free(buf); break; @@ -284,6 +290,7 @@ load_dir(char *name) ; } } +done: closedir(dirp); } diff --git a/libexec/ld.so/ldconfig/prebind_delete.c b/libexec/ld.so/ldconfig/prebind_delete.c index bc5eb77cad4..bbe5a9f3780 100644 --- a/libexec/ld.so/ldconfig/prebind_delete.c +++ b/libexec/ld.so/ldconfig/prebind_delete.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind_delete.c,v 1.12 2013/05/04 09:23:33 jsg Exp $ */ +/* $OpenBSD: prebind_delete.c,v 1.13 2015/06/03 02:24:36 millert Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> @@ -101,14 +101,22 @@ strip_dir(char *dir) * NFS will return unknown, since load_file * does stat the file, this just */ - asprintf(&buf, "%s/%s", dir, dp->d_name); + if (asprintf(&buf, "%s/%s", dir, dp->d_name) == -1) { + if (verbose) + warn("asprintf"); + goto done; + } lstat(buf, &sb); if (sb.st_mode == S_IFREG) ret = strip_prebind(buf); free(buf); break; case DT_REG: - asprintf(&buf, "%s/%s", dir, dp->d_name); + if (asprintf(&buf, "%s/%s", dir, dp->d_name) == -1) { + if (verbose) + warn("asprintf"); + goto done; + } ret = strip_prebind(buf); free(buf); break; @@ -118,6 +126,7 @@ strip_dir(char *dir) ; } } +done: closedir(dirp); return ret; } |