File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ static __wasi_errno_t populate_args(size_t *argc, char **argv) {
1717 if (err != __WASI_ESUCCESS ) {
1818 return err ;
1919 }
20+ if (* argc == 0 ) {
21+ return __WASI_ESUCCESS ;
22+ }
2023
2124 /* Allocate memory for the array of pointers. */
2225 argv = malloc (sizeof (char * ) * * argc );
@@ -40,9 +43,14 @@ static __wasi_errno_t populate_environ() {
4043 if (err != __WASI_ESUCCESS ) {
4144 return err ;
4245 }
46+ /* If there's no environment pairs, make sure environ is null and return. */
47+ if (environ_count == 0 ) {
48+ environ = NULL ;
49+ return __WASI_ESUCCESS ;
50+ }
4351
44- /* Allocate memory for the array of pointers. */
45- environ = malloc (sizeof (char * ) * environ_count );
52+ /* Allocate memory for the array of pointers, plus one terminating null pointer . */
53+ environ = malloc (sizeof (char * ) * ( environ_count + 1 ) );
4654 /* Allocate memory for storing the environment chars. */
4755 char * environ_buf = malloc (sizeof (char ) * environ_size );
4856 if (environ == NULL || environ_buf == NULL ) {
You can’t perform that action at this time.
0 commit comments