Protect mysetenv() fron any NULL string pointers

...such as those we seem to be receiving from _nl_locale_name()
on 64-bit Windows under newer MinGW/MSYS (see big thread on
tuxpaint-devel with reports from Shin-ichi).
This commit is contained in:
Bill Kendrick 2021-10-25 22:11:32 -07:00
parent 9c010ffd40
commit 1bee12246e

View file

@ -25,7 +25,7 @@
$Id$
June 14, 2002 - July 26, 2020
June 14, 2002 - October 25, 2021
*/
#include <stdio.h>
@ -966,14 +966,26 @@ static void set_langint_from_locale_string(const char *restrict loc)
static void mysetenv(const char *name, const char *value)
{
#ifdef HAVE_SETENV
setenv(name, value, 1);
#else
int len = strlen(name) + 1 + strlen(value) + 1;
char *str = malloc(len);
sprintf(str, "%s=%s", name, value);
putenv(str);
int len;
char *str;
#endif
if (name != NULL && value != NULL) {
#ifdef HAVE_SETENV
setenv(name, value, 1);
#else
len = strlen(name) + 1 + strlen(value) + 1;
str = malloc(len);
sprintf(str, "%s=%s", name, value);
putenv(str);
#endif
} else {
fprintf(stderr, "WARNING: mysetenv() received a null pointer. name=%s, value=%s\n",
(name == NULL ? "NULL" : name),
(value == NULL ? "NULL" : value)
);
}
}