[commit: ghc] master: linker/mach-o: Catch the case where there is no symCmd (6c05b27)

git at git.haskell.org git at git.haskell.org
Sun Apr 16 01:30:46 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/6c05b27e5bafe9f232e7014f4760335f5e3ba591/ghc

>---------------------------------------------------------------

commit 6c05b27e5bafe9f232e7014f4760335f5e3ba591
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Sat Apr 15 21:30:10 2017 -0400

    linker/mach-o: Catch the case where there is no symCmd
    
    We do check for symCmd, to set the info->nlist value, but
    forgot to do the same check for info->names.  Thus when trying to
    extract stroff from symCmd, we hit a segfault.
    
    Reviewers: bgamari, adinapoli, austin, erikd, simonmar
    
    Reviewed By: bgamari, adinapoli
    
    Subscribers: rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3459


>---------------------------------------------------------------

6c05b27e5bafe9f232e7014f4760335f5e3ba591
 rts/Linker.c       | 2 ++
 rts/linker/MachO.c | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 7366904..b214e9c 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1215,6 +1215,8 @@ mkOc( pathchar *path, char *image, int imageSize,
    IF_DEBUG(linker, debugBelch("mkOc: start\n"));
    oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)");
 
+   oc->info = NULL;
+
 #  if defined(OBJFORMAT_ELF)
    oc->formatName = "ELF";
 #  elif defined(OBJFORMAT_PEi386)
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 16b712a..e09d151 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -130,7 +130,9 @@ ocInit_MachO(ObjectCode * oc)
     oc->info->nlist = oc->info->symCmd == NULL
               ? NULL
               : (MachONList *)(oc->image + oc->info->symCmd->symoff);
-    oc->info->names = oc->image + oc->info->symCmd->stroff;
+    oc->info->names = oc->info->symCmd == NULL
+              ? NULL
+              : (oc->image + oc->info->symCmd->stroff);
 
     /* If we have symbols, allocate and fill the macho_symbols
      * This will make relocation easier.



More information about the ghc-commits mailing list