diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-11 23:24:40 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-11 23:24:40 +0000 |
commit | 705c579cdb226f203ba43dabbf40cae075780aad (patch) | |
tree | 2af6ad7e8488c10e8d0a60fe4bd97e97edbc981f /gnu/usr.bin/ld | |
parent | 3ea968582de7b7ba19dc2d93dc3b8c459a6667f7 (diff) |
o Check mmap() return value against MAP_FAILED, not -1.
o Prevent close() from clobbering errno.
Patch from Peter Werner; closes PR 2995
Diffstat (limited to 'gnu/usr.bin/ld')
-rw-r--r-- | gnu/usr.bin/ld/rtld/malloc.c | 6 | ||||
-rw-r--r-- | gnu/usr.bin/ld/rtld/rtld.c | 19 |
2 files changed, 16 insertions, 9 deletions
diff --git a/gnu/usr.bin/ld/rtld/malloc.c b/gnu/usr.bin/ld/rtld/malloc.c index ad1cf263fd0..93f7ff58aef 100644 --- a/gnu/usr.bin/ld/rtld/malloc.c +++ b/gnu/usr.bin/ld/rtld/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.7 2002/11/29 22:31:41 deraadt Exp $ */ +/* $OpenBSD: malloc.c,v 1.8 2002/12/11 23:24:39 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -35,7 +35,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/ -static char *rcsid = "$OpenBSD: malloc.c,v 1.7 2002/11/29 22:31:41 deraadt Exp $"; +static char *rcsid = "$OpenBSD: malloc.c,v 1.8 2002/12/11 23:24:39 millert Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -463,7 +463,7 @@ morepages(int n) if ((pagepool_start = mmap(0, n * pagesz, PROT_READ|PROT_WRITE, - MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) { + MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)MAP_FAILED) { xprintf("Cannot map anonymous memory"); return 0; } diff --git a/gnu/usr.bin/ld/rtld/rtld.c b/gnu/usr.bin/ld/rtld/rtld.c index 1e0f74c7eeb..08e095753f2 100644 --- a/gnu/usr.bin/ld/rtld/rtld.c +++ b/gnu/usr.bin/ld/rtld/rtld.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld.c,v 1.31 2002/12/02 23:17:36 deraadt Exp $ */ +/* $OpenBSD: rtld.c,v 1.32 2002/12/11 23:24:39 millert Exp $ */ /* $NetBSD: rtld.c,v 1.43 1996/01/14 00:35:17 pk Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg @@ -551,7 +551,7 @@ map_object(struct sod *sodp, struct so_map *smp) char *name; struct _dynamic *dp; char *path, *ipath; - int fd; + int fd, sverrno; caddr_t addr; struct exec hdr; int usehints = 0; @@ -606,8 +606,9 @@ again: } if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) { + sverrno = errno; (void)close(fd); - /*errno = x;*/ + errno = sverrno; return NULL; } @@ -619,8 +620,10 @@ again: if ((addr = mmap(0, hdr.a_text + hdr.a_data + hdr.a_bss, PROT_READ|PROT_EXEC, - MAP_COPY, fd, 0)) == (caddr_t)-1) { + MAP_COPY, fd, 0)) == (caddr_t)MAP_FAILED) { + sverrno = errno; (void)close(fd); + errno = sverrno; return NULL; } @@ -630,15 +633,19 @@ again: if (mprotect(addr + hdr.a_text, hdr.a_data, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) { + sverrno = errno; (void)close(fd); + errno = sverrno; return NULL; } if (mmap(addr + hdr.a_text + hdr.a_data, hdr.a_bss, PROT_READ|PROT_WRITE, MAP_ANON|MAP_COPY|MAP_FIXED, - anon_fd, 0) == (caddr_t)-1) { + anon_fd, 0) == (caddr_t)MAP_FAILED) { + sverrno = errno; (void)close(fd); + errno = sverrno; return NULL; } @@ -1157,7 +1164,7 @@ maphints(void) hsize = PAGSIZ; addr = mmap(0, hsize, PROT_READ, MAP_COPY, hfd, 0); - if (addr == (caddr_t)-1) { + if (addr == (caddr_t)MAP_FAILED) { close(hfd); hheader = (struct hints_header *)-1; return; |