From: tobias Date: Fri, 16 Oct 2015 16:54:38 +0000 (+0000) Subject: Check file sizes only for regular files. The current code breaks savecore X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1b9417bb627d90cee2fed3f82e34d8d0524f485b;p=openbsd Check file sizes only for regular files. The current code breaks savecore due to its kvm handling. ok deraadt --- 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 #include #include +#include #include #include @@ -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); }