changeset 42962:d6227c6c0814

osutil: tolerate Py_GetArgcArgv not being set up properly Differential Revision: https://phab.mercurial-scm.org/D6866
author Kyle Lippincott <spectral@google.com>
date Tue, 17 Sep 2019 15:09:25 -0700
parents 460f8bf58020
children 8502f76dbfd7
files mercurial/cext/osutil.c
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/osutil.c	Tue Sep 17 14:57:42 2019 -0700
+++ b/mercurial/cext/osutil.c	Tue Sep 17 15:09:25 2019 -0700
@@ -798,10 +798,17 @@
 			char *argvend;
 			extern void Py_GetArgcArgv(int *argc, char ***argv);
 			Py_GetArgcArgv(&argc, &argv);
+			/* Py_GetArgcArgv may not do much if a custom python
+			 * launcher is used that doesn't record the information
+			 * it needs. Let's handle this gracefully instead of
+			 * segfaulting. */
+			if (argv != NULL)
+				argvend = argvstart = argv[0];
+			else
+				argvend = argvstart = NULL;
 
 			/* Check the memory we can use. Typically, argv[i] and
 			 * argv[i + 1] are continuous. */
-			argvend = argvstart = argv[0];
 			for (i = 0; i < argc; ++i) {
 				if (argv[i] > argvend || argv[i] < argvstart)
 					break; /* not continuous */