From 7eff4e7c1d40b4f6666aa8b635f30d8f6771e88f Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 4 Dec 2017 09:23:06 -0600 Subject: [PATCH] Terminate options when passed via env var The C standard requires that argv be terminated with a NULL pointer (that is, argv[argc] == NULL). There are several places in the swig codebase that require this to check for missing arguments. However, SWIG_merge_envopt() was not keeping the NULL terminator, resulting in argument parsing failures (typically program aborts) when arguments were passed via the SWIG_FEATURES environment variable. --- Source/Modules/swigmain.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 397677fc5..b49fe909a 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -125,7 +125,7 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, ch int argc = 1; int arge = oargc + 1024; - char **argv = (char **) malloc(sizeof(char *) * (arge)); + char **argv = (char **) malloc(sizeof(char *) * (arge + 1)); char *buffer = (char *) malloc(2048); char *b = buffer; char *be = b + 1023; @@ -147,6 +147,7 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, ch for (int i = 1; (i < oargc) && (argc < arge); ++i, ++argc) { argv[argc] = oargv[i]; } + argv[argc] = NULL; *nargc = argc; *nargv = argv;