aboutsummaryrefslogtreecommitdiff
path: root/src/apps/optargpm.h
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2022-02-19 12:34:25 +0100
committerEven Rouault <even.rouault@spatialys.com>2022-02-19 12:38:28 +0100
commit61249e6606513295b9ba5ad9a42cbb3601694d13 (patch)
treeec59d181e9b98c34c745bbe15c6073515d9f8fea /src/apps/optargpm.h
parent524b76f2e9f4bb8e4a8d2a4287c23e67c67fce07 (diff)
downloadPROJ-61249e6606513295b9ba5ad9a42cbb3601694d13.tar.gz
PROJ-61249e6606513295b9ba5ad9a42cbb3601694d13.zip
Fix nullptr dereference in utilities whan argv[0] == NULL
https://lwn.net/Articles/?offset=50 was an entertaining reading where we learn that the fact that argv[0] contains the name of the binary is purely a convention, normally taken by the shell that launches the process, but not guaranteed by the execve() system call that does the job. The following test program tested against cct, cs2cs, geod, gie and proj make them cause a null pointer dereference ``` #include <unistd.h> #include <stdio.h> extern char **environ; int main() { char* argv[] = { NULL }; printf("%d\n", execve("/path/to/some/proj/binary", argv, environ)); return 0; } ```
Diffstat (limited to 'src/apps/optargpm.h')
-rw-r--r--src/apps/optargpm.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/apps/optargpm.h b/src/apps/optargpm.h
index 9a66b9a0..921b8c0b 100644
--- a/src/apps/optargpm.h
+++ b/src/apps/optargpm.h
@@ -415,6 +415,9 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
int free_format;
OPTARGS *o;
+ if( argc == 0 )
+ return nullptr;
+
o = (OPTARGS *) calloc (1, sizeof(OPTARGS));
if (nullptr==o)
return nullptr;