[GHC] #7037: setProgName() crashes when argv[0] == NULL
GHC
cvs-ghc at haskell.org
Sat Jun 30 08:55:22 CEST 2012
#7037: setProgName() crashes when argv[0] == NULL
------------------------------+---------------------------------------------
Reporter: shachaf | Owner:
Type: bug | Status: new
Priority: normal | Component: Runtime System
Version: 7.4.2 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: Runtime crash | Testcase:
Blockedby: | Blocking:
Related: |
------------------------------+---------------------------------------------
C89 allows {{{argc}}} to be 0, in which case {{{argv[0]}}} is {{{NULL}}}.
This can happen in practice in Linux+glibc with {{{execve(program, {NULL},
...);}}}.
The RTS assumes that {{{argv[0]}}} always points to a valid string:
{{{void setProgName(char *argv[]) { char *last_slash; if ( (last_slash =
(char *) strrchr(argv[0], '/')) != NULL ) { ... } else { ... } }}}}.
This means that any GHC-compiled program can be made to segfault with
{{{execl("./ghc-compiled-program", NULL);}}}.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7037>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list