diff options
author | 2002-07-30 22:47:22 +0000 | |
---|---|---|
committer | 2002-07-30 22:47:22 +0000 | |
commit | f72f9a8f6c1646bce5d20a7de2bc22e7d300ac86 (patch) | |
tree | 735cbcf4671068eec9bfd7c3e4e01d51fffa4017 /lib/libc/gen | |
parent | for the disabled DSTORAGE option, fix the local calloc() here in the same way as libc; eugene@securityarchitects.com (diff) | |
download | wireguard-openbsd-f72f9a8f6c1646bce5d20a7de2bc22e7d300ac86.tar.xz wireguard-openbsd-f72f9a8f6c1646bce5d20a7de2bc22e7d300ac86.zip |
malloc paranoia; it is unlikely that any filesystem will support
enough directory entries to cause a problem but it is good form anyway.
deraadt@ OK.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/opendir.c | 5 | ||||
-rw-r--r-- | lib/libc/gen/scandir.c | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index d9dcb77306e..ffeb29246d5 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: opendir.c,v 1.7 2002/07/08 20:23:14 millert Exp $"; +static char rcsid[] = "$OpenBSD: opendir.c,v 1.8 2002/07/30 22:47:22 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -42,6 +42,7 @@ static char rcsid[] = "$OpenBSD: opendir.c,v 1.7 2002/07/08 20:23:14 millert Exp #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <limits.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -253,6 +254,8 @@ __opendir2(name, flags) free(dpv); break; } else { + if (n+1 > SIZE_T_MAX / sizeof(struct dirent *)) + break; dpv = malloc((n+1) * sizeof(struct dirent *)); if (dpv == NULL) break; diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 10ab99dd52c..0f5c62ce150 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: scandir.c,v 1.5 2002/02/16 21:27:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: scandir.c,v 1.6 2002/07/30 22:47:22 millert Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -45,6 +45,8 @@ static char rcsid[] = "$OpenBSD: scandir.c,v 1.5 2002/02/16 21:27:23 millert Exp #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> +#include <errno.h> +#include <limits.h> #include <stdlib.h> #include <string.h> @@ -82,6 +84,10 @@ scandir(dirname, namelist, select, dcomp) * and dividing it by a multiple of the minimum size entry. */ arraysz = (stb.st_size / 24); + if (arraysz > SIZE_T_MAX / sizeof(struct dirent *)) { + errno = ENOMEM; + return(-1); + } names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); if (names == NULL) return(-1); |