summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/getusershell.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2012-04-06 20:54:41 +0000
committerderaadt <deraadt@openbsd.org>2012-04-06 20:54:41 +0000
commitb5ce4011f41afcf3a7516c6276fd41377f0fc683 (patch)
tree9d1d6747fd116464b3a3b3734378f19698eaaa88 /lib/libc/gen/getusershell.c
parentMinimal threads debug support; enough to make attach and detach work. (diff)
downloadwireguard-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.c10
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);