Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libelf/dist Add some range checks to quiet warn...



details:   https://anonhg.NetBSD.org/src/rev/a651bf5fa9a1
branches:  trunk
changeset: 750168:a651bf5fa9a1
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Dec 19 09:00:56 2009 +0000

description:
Add some range checks to quiet warnings.

diffstat:

 external/bsd/libelf/dist/libelf_ehdr.c |  21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diffs (54 lines):

diff -r cb28893efd76 -r a651bf5fa9a1 external/bsd/libelf/dist/libelf_ehdr.c
--- a/external/bsd/libelf/dist/libelf_ehdr.c    Sat Dec 19 08:47:46 2009 +0000
+++ b/external/bsd/libelf/dist/libelf_ehdr.c    Sat Dec 19 09:00:56 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libelf_ehdr.c,v 1.2 2009/12/19 05:55:37 thorpej Exp $  */
+/*     $NetBSD: libelf_ehdr.c,v 1.3 2009/12/19 09:00:56 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2006 Joseph Koshy
@@ -30,11 +30,12 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libelf/libelf_ehdr.c,v 1.2.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $"); */
-__RCSID("$NetBSD: libelf_ehdr.c,v 1.2 2009/12/19 05:55:37 thorpej Exp $");
+__RCSID("$NetBSD: libelf_ehdr.c,v 1.3 2009/12/19 09:00:56 thorpej Exp $");
 
 #include <assert.h>
 #include <gelf.h>
 #include <libelf.h>
+#include <limits.h>
 #include <stdlib.h>
 
 #include "_libelf.h"
@@ -65,9 +66,14 @@
        if ((scn = _libelf_allocate_scn(e, (size_t) 0)) == NULL)
                return (0);
 
+       if (shoff > SSIZE_MAX) {
+               LIBELF_SET_ERROR(HEADER, 0);
+               return (0);
+       }
+
        xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
-       (*xlator)((char *) &scn->s_shdr, e->e_rawfile + shoff, (size_t) 1,
-           e->e_byteorder != LIBELF_PRIVATE(byteorder));
+       (*xlator)((void *) &scn->s_shdr, e->e_rawfile + (ssize_t)shoff,
+           (size_t) 1, e->e_byteorder != LIBELF_PRIVATE(byteorder));
 
 #define        GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \
                scn->s_shdr.s_shdr64.M)
@@ -77,7 +83,12 @@
                return (0);
        }
 
-       e->e_u.e_elf.e_nscn = GET_SHDR_MEMBER(sh_size);
+       if (GET_SHDR_MEMBER(sh_size) > UINT_MAX) {
+               LIBELF_SET_ERROR(HEADER, 0);
+               return (0);
+       }
+
+       e->e_u.e_elf.e_nscn = (unsigned int)GET_SHDR_MEMBER(sh_size);
        e->e_u.e_elf.e_nphdr = (phnum != PN_XNUM) ? phnum :
            GET_SHDR_MEMBER(sh_info);
        e->e_u.e_elf.e_strndx = (strndx != SHN_XINDEX) ? strndx :



Home | Main Index | Thread Index | Old Index