pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryan Green <dbryan.green@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: [PATCH] Fix POSIX compliance in pgwin32_unsetenv()
Date: Sat, 18 Oct 2025 13:26:40 -0500
Message-ID: <b6a1e52b-d808-4df7-87f7-2ff48d15003e@gmail.com> (raw)

I noticed that pgwin32_unsetenv() in src/port/win32env.c lacks the input 
validation that its sibling function pgwin32_setenv() has (lines 126-132).

Without these checks, the function will crash on NULL input via 
strlen(NULL), and will accept empty strings or strings containing '=' in 
violation of POSIX.1-2008.

The attached patch adds the same validation that pgwin32_setenv already 
does, making the two functions consistent.  This is purely defensive - 
it only affects callers passing invalid arguments.

regards,

Bryan Green

Attachments:

0001-Fix-POSIX-compliance-in-pgwin32_unsetenv.patch (text/plain, 1.0K) download From dda02bef12a725eff5e38367f2a525b2355c29d0 Mon Sep 17 00:00:00 2001 From: Bryan Green <dbryan.green@gmail.com> Date: Sat, 18 Oct 2025 13:04:04 -0500 Subject: [PATCH] Fix POSIX compliance in pgwin32_unsetenv() pgwin32_unsetenv() lacks the input validation that its sibling pgwin32_setenv() has. Add the same checks for NULL, empty string, and '=' in the name parameter, per POSIX requirements. Without these checks, unsetenv(NULL) crashes, and invalid names are accepted when they should fail with EINVAL. --- src/port/win32env.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/port/win32env.c b/src/port/win32env.c index b22fbafde4..e1cee683db 100644 --- a/src/port/win32env.c +++ b/src/port/win32env.c @@ -152,6 +152,13 @@ pgwin32_unsetenv(const char *name) int res; char *envbuf; + /* Error conditions, per POSIX */ + if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) + { + errno = EINVAL; + return -1; + } + envbuf = (char *) malloc(strlen(name) + 2); if (!envbuf) return -1; -- 2.49.0

view thread (4+ messages)  latest in thread

Message-ID: <b6a1e52b-d808-4df7-87f7-2ff48d15003e@gmail.com>
Permalink:  ../b6a1e52b-d808-4df7-87f7-2ff48d15003e@gmail.com/
Also on:    postgresql.org/message-id/b6a1e52b-d808-4df7-87f7-2ff48d15003e@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: dbryan.green@gmail.com
  Subject: Re: [PATCH] Fix POSIX compliance in pgwin32_unsetenv()
  In-Reply-To: <b6a1e52b-d808-4df7-87f7-2ff48d15003e@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox