Commits

Anonymous committed e8f6b51 Merge

Merge branch 'ef/setenv-putenv' into maint

* ef/setenv-putenv:
compat/setenv.c: error if name contains '='
compat/setenv.c: update errno when erroring out

  • Participants
  • Parent commits 3c06ab6, 6ac1b2a

Comments (0)

Files changed (1)

File compat/setenv.c

 	size_t namelen, valuelen;
 	char *envstr;
 
-	if (!name || !value) return -1;
+	if (!name || strchr(name, '=') || !value) {
+		errno = EINVAL;
+		return -1;
+	}
 	if (!replace) {
 		char *oldval = NULL;
 		oldval = getenv(name);
 	namelen = strlen(name);
 	valuelen = strlen(value);
 	envstr = malloc((namelen + valuelen + 2));
-	if (!envstr) return -1;
+	if (!envstr) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	memcpy(envstr, name, namelen);
 	envstr[namelen] = '=';