Module Name:    src
Committed By:   christos
Date:           Thu Sep  2 17:10:15 UTC 2010

Modified Files:
        src/sys/lib/libsa: loadfile_elf32.c

Log Message:
PR/43830: Valery Ushakov: libsa/loadfile_elf32.c loads .shstrtab into
unallocated memory. Don't load if counting.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/lib/libsa/loadfile_elf32.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/lib/libsa/loadfile_elf32.c
diff -u src/sys/lib/libsa/loadfile_elf32.c:1.25 src/sys/lib/libsa/loadfile_elf32.c:1.26
--- src/sys/lib/libsa/loadfile_elf32.c:1.25	Fri Mar 12 16:43:11 2010
+++ src/sys/lib/libsa/loadfile_elf32.c	Thu Sep  2 13:10:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile_elf32.c,v 1.25 2010/03/12 21:43:11 darran Exp $ */
+/* $NetBSD: loadfile_elf32.c,v 1.26 2010/09/02 17:10:14 christos Exp $ */
 
 /*-
  * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc.
@@ -411,36 +411,40 @@
 		 * First load the section names section.
 		 */
 		if (boot_load_ctf && (elf->e_shstrndx != 0)) {
-		    if (lseek(fd, shp[elf->e_shstrndx].sh_offset,
-			SEEK_SET) == -1) {
-			    WARN(("lseek symbols"));
-			    goto freeshp;
-		    }
-		    nr = READ(fd, maxp, shp[elf->e_shstrndx].sh_size);
-		    if (nr == -1) {
-			    WARN(("read symbols"));
-			    goto freeshp;
-		    }
-		    if (nr != (ssize_t)shp[elf->e_shstrndx].sh_size) {
-			    errno = EIO;
-			    WARN(("read symbols"));
-			    goto freeshp;
-		    }
-
-		    shstr = ALLOC(shp[elf->e_shstrndx].sh_size);
-		    if (lseek(fd, shp[elf->e_shstrndx].sh_offset,
-			SEEK_SET) == -1) {
-			    WARN(("lseek symbols"));
-			    goto freeshp;
-		    }
-		    nr = read(fd, shstr, shp[elf->e_shstrndx].sh_size);
-		    if (nr == -1) {
-			    WARN(("read symbols"));
-			    goto freeshp;
-		    }
+			if (flags & LOAD_SYM) {
+				if (lseek(fd, shp[elf->e_shstrndx].sh_offset,
+				    SEEK_SET) == -1) {
+					WARN(("lseek symbols"));
+					goto freeshp;
+				}
+				nr = READ(fd, maxp,
+				    shp[elf->e_shstrndx].sh_size);
+				if (nr == -1) {
+					WARN(("read symbols"));
+					goto freeshp;
+				}
+				if (nr !=
+				    (ssize_t)shp[elf->e_shstrndx].sh_size) {
+					errno = EIO;
+					WARN(("read symbols"));
+					goto freeshp;
+				}
 
-		    shp[elf->e_shstrndx].sh_offset = maxp - elfp;
-		    maxp += roundup(shp[elf->e_shstrndx].sh_size, ELFROUND);
+				shstr = ALLOC(shp[elf->e_shstrndx].sh_size);
+				if (lseek(fd, shp[elf->e_shstrndx].sh_offset,
+				    SEEK_SET) == -1) {
+					WARN(("lseek symbols"));
+					goto freeshp;
+				}
+				nr = read(fd, shstr,
+				    shp[elf->e_shstrndx].sh_size);
+				if (nr == -1) {
+					WARN(("read symbols"));
+					goto freeshp;
+				}
+			}
+			shp[elf->e_shstrndx].sh_offset = maxp - elfp;
+			maxp += roundup(shp[elf->e_shstrndx].sh_size, ELFROUND);
 		}
 
 		/*

Reply via email to