diff options
author | 2015-10-16 16:54:38 +0000 | |
---|---|---|
committer | 2015-10-16 16:54:38 +0000 | |
commit | 1b9417bb627d90cee2fed3f82e34d8d0524f485b (patch) | |
tree | 95f54d9f7ec4f290f4467c183a7eea397583bae3 | |
parent | Pledge the syslogd privsep process with "stdio rpath wpath cpath (diff) | |
download | wireguard-openbsd-1b9417bb627d90cee2fed3f82e34d8d0524f485b.tar.xz wireguard-openbsd-1b9417bb627d90cee2fed3f82e34d8d0524f485b.zip |
Check file sizes only for regular files. The current code breaks savecore
due to its kvm handling.
ok deraadt
-rw-r--r-- | distrib/common/elfrd_size.c | 5 | ||||
-rw-r--r-- | lib/libc/gen/nlist.c | 6 | ||||
-rw-r--r-- | usr.sbin/installboot/i386_nlist.c | 6 |
3 files changed, 9 insertions, 8 deletions
diff --git a/distrib/common/elfrd_size.c b/distrib/common/elfrd_size.c index 58458012f7e..01ce5dc4956 100644 --- a/distrib/common/elfrd_size.c +++ b/distrib/common/elfrd_size.c @@ -6,6 +6,7 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <nlist.h> @@ -192,7 +193,7 @@ ELFNAME(nlist)(int fd, struct nlist *list) /* Make sure it's not too big to mmap */ if (SIZE_MAX - ehdr.e_shoff < shdr_size || - ehdr.e_shoff + shdr_size > st.st_size) { + S_ISREG(st.st_mode) && ehdr.e_shoff + shdr_size > st.st_size) { errno = EFBIG; return (-1); } @@ -262,7 +263,7 @@ ELFNAME(nlist)(int fd, struct nlist *list) /* Check for files too large to mmap. */ if (SIZE_MAX - symstrsize < symstroff || - symstrsize + symstroff > st.st_size) { + S_ISREG(st.st_mode) && symstrsize + symstroff > st.st_size) { errno = EFBIG; return (-1); } diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index 437640732d1..f76543bf8fd 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nlist.c,v 1.64 2015/10/16 13:54:45 tobias Exp $ */ +/* $OpenBSD: nlist.c,v 1.65 2015/10/16 16:54:38 tobias Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -107,7 +107,7 @@ __fdnlist(int fd, struct nlist *list) /* Make sure it's not too big to mmap */ if (SIZE_MAX - ehdr.e_shoff < shdr_size || - ehdr.e_shoff + shdr_size > st.st_size) { + (S_ISREG(st.st_mode) && ehdr.e_shoff + shdr_size > st.st_size)) { errno = EFBIG; return (-1); } @@ -177,7 +177,7 @@ __fdnlist(int fd, struct nlist *list) /* Check for files too large to mmap. */ if (SIZE_MAX - symstrsize < symstroff || - symstrsize + symstroff > st.st_size) { + (S_ISREG(st.st_mode) && symstrsize + symstroff > st.st_size)) { errno = EFBIG; return (-1); } diff --git a/usr.sbin/installboot/i386_nlist.c b/usr.sbin/installboot/i386_nlist.c index 9d5950dcbf7..c5a32055f7e 100644 --- a/usr.sbin/installboot/i386_nlist.c +++ b/usr.sbin/installboot/i386_nlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i386_nlist.c,v 1.3 2015/10/16 13:54:45 tobias Exp $ */ +/* $OpenBSD: i386_nlist.c,v 1.4 2015/10/16 16:54:38 tobias Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -117,7 +117,7 @@ __elf_fdnlist(int fd, struct nlist *list) /* Make sure it's not too big to mmap */ if (SIZE_MAX - ehdr.e_shoff < shdr_size || - ehdr.e_shoff + shdr_size > st.st_size) { + S_ISREG(st.st_mode) && ehdr.e_shoff + shdr_size > st.st_size) { errno = EFBIG; return (-1); } @@ -187,7 +187,7 @@ __elf_fdnlist(int fd, struct nlist *list) /* Check for files too large to mmap. */ if (SIZE_MAX - symstrsize < symstroff || - symstrsize + symstroff > st.st_size) { + S_ISREG(st.st_mode) && symstrsize + symstroff > st.st_size) { errno = EFBIG; return (-1); } |