From: sof Date: Sat, 8 Aug 1998 17:38:42 +0000 (+0000) Subject: [project @ 1998-08-08 17:38:42 by sof] X-Git-Tag: Approx_2487_patches~470 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=4aa09bc17e6aa7a876bd9b362cc5c30fbee16736;p=ghc-hetmet.git [project @ 1998-08-08 17:38:42 by sof] _setenv: off by one error when extending the env block. (has this code ever been used in anger?) --- diff --git a/ghc/lib/posix/cbits/env.c b/ghc/lib/posix/cbits/env.c index 936039c..79a85e7 100644 --- a/ghc/lib/posix/cbits/env.c +++ b/ghc/lib/posix/cbits/env.c @@ -68,7 +68,8 @@ copyenv(void) char **new; int i; - for (i = 0; environ[i] != NULL; i++); + for (i = 0; environ[i] != NULL; i++) + ; if ((new = (char **) malloc((i + 1) * sizeof(char *))) == NULL) return -1; @@ -120,7 +121,8 @@ _setenv(char *mapping) free(environ[i]); environ[i] = p; } else { - if ((new = (char **) realloc(environ, (i + 1) * sizeof(char *))) == NULL) { + /* We want to grow the table by *two*, one for the new entry, one for the terminator */ + if ((new = (char **) realloc((void*)environ, (i + 2) * sizeof(char *))) == NULL) { free(p); return -1; }