Skip to content

Commit 29b039e

Browse files
committed
Fix POSIX compliance in pgwin32_unsetenv() for "name" argument
pgwin32_unsetenv() (compatibility routine of unsetenv() on Windows) lacks the input validation that its sibling pgwin32_setenv() has. Without these checks, calling unsetenv() with incorrect names crashes on WIN32. However, invalid names should be handled, failing on EINVAL. This commit adds the same checks as setenv() to fail with EINVAL for a "name" set to NULL, an empty string, or if '=' is included in the value, per POSIX requirements. Like 7ca37fb, backpatch down to v14. pgwin32_unsetenv() is defined on REL_13_STABLE, but with the branch going EOL soon and the lack of setenv() there for WIN32, nothing is done for v13. Author: Bryan Green <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 14
1 parent 4bea91f commit 29b039e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/port/win32env.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ pgwin32_unsetenv(const char *name)
152152
int res;
153153
char *envbuf;
154154

155+
/* Error conditions, per POSIX */
156+
if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL)
157+
{
158+
errno = EINVAL;
159+
return -1;
160+
}
161+
155162
envbuf = (char *) malloc(strlen(name) + 2);
156163
if (!envbuf)
157164
return -1;

0 commit comments

Comments
 (0)