Source-Changes-HG archive

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

[src/trunk]: src/lib/csu/common i386/amd64 build fix. Fix "possibly used un...



details:   https://anonhg.NetBSD.org/src/rev/e5921268331d
branches:  trunk
changeset: 320585:e5921268331d
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Jul 13 01:00:17 2018 +0000

description:
i386/amd64 build fix.   Fix "possibly used uninitialized" from gcc.
These changes should make no practical effect - but because external
data is being examined, it would be possible to contrive a situation
(perhaps) where uninit'd vars could actually be used (unless the format
has been checked elsewhere earlier - I did not look ... we have to
appease gcc anyway).

Joerg: Please review (& fix)

diffstat:

 lib/csu/common/crt0-common.c |  19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 3c4bff491c17 -r e5921268331d lib/csu/common/crt0-common.c
--- a/lib/csu/common/crt0-common.c      Thu Jul 12 23:18:28 2018 +0000
+++ b/lib/csu/common/crt0-common.c      Fri Jul 13 01:00:17 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.19 2018/07/13 01:00:17 kre Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.19 2018/07/13 01:00:17 kre Exp $");
 
 #include <sys/types.h>
 #include <sys/exec.h>
@@ -214,9 +214,9 @@
 {
        AuxInfo *aux = (AuxInfo *)(ps_strings->ps_argvstr + ps_strings->ps_nargvstr +
            ps_strings->ps_nenvstr + 2);
-       uintptr_t relocbase;
-       const Elf_Phdr *phdr;
-       Elf_Half phnum;
+       uintptr_t relocbase = (uintptr_t)~0U;
+       const Elf_Phdr *phdr = NULL;
+       Elf_Half phnum = (Elf_Half)~0;
 
        for (; aux->a_type != AT_NULL; ++aux) {
                switch (aux->a_type) {
@@ -232,7 +232,11 @@
                        break;
                }
        }
-       const Elf_Phdr *phlimit = phdr + phnum, *dynphdr;
+
+       if (phdr == NULL || phnum == (Elf_Half)~0)
+               return;
+
+       const Elf_Phdr *phlimit = phdr + phnum, *dynphdr = NULL;
 
        for (; phdr < phlimit; ++phdr) {
                if (phdr->p_type == PT_DYNAMIC)
@@ -240,6 +244,9 @@
                if (phdr->p_type == PT_PHDR)
                        relocbase = (uintptr_t)phdr - phdr->p_vaddr;
        }
+       if (dynphdr == NULL || relocbase == (uintptr_t)~0U)
+               return;
+
        Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);
 
        const REL_TYPE *relocs = 0, *relocslim;



Home | Main Index | Thread Index | Old Index