diff options
author | 2012-04-06 20:54:41 +0000 | |
---|---|---|
committer | 2012-04-06 20:54:41 +0000 | |
commit | b5ce4011f41afcf3a7516c6276fd41377f0fc683 (patch) | |
tree | 9d1d6747fd116464b3a3b3734378f19698eaaa88 /lib/libc/gen/getusershell.c | |
parent | Minimal threads debug support; enough to make attach and detach work. (diff) | |
download | wireguard-openbsd-b5ce4011f41afcf3a7516c6276fd41377f0fc683.tar.xz wireguard-openbsd-b5ce4011f41afcf3a7516c6276fd41377f0fc683.zip |
range check st_size before calling calloc()
ok millert
Diffstat (limited to 'lib/libc/gen/getusershell.c')
-rw-r--r-- | lib/libc/gen/getusershell.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index 200c78c66bc..4d6a178addf 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getusershell.c,v 1.8 2005/08/08 08:05:34 espie Exp $ */ +/* $OpenBSD: getusershell.c,v 1.9 2012/04/06 20:54:41 deraadt Exp $ */ /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. @@ -101,11 +101,15 @@ initshells(void) (void)fclose(fp); return (okshells); } - if ((strings = malloc((u_int)statb.st_size)) == NULL) { + if (statb.st_size > SIZE_T_MAX) { (void)fclose(fp); return (okshells); } - shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); + if ((strings = malloc((size_t)statb.st_size)) == NULL) { + (void)fclose(fp); + return (okshells); + } + shells = calloc((size_t)(statb.st_size / 3), sizeof (char *)); if (shells == NULL) { (void)fclose(fp); free(strings); |