Re: Missing NULL check after calling ecpg_strdup
Aleksander Alekseev <aleksander@tigerdata.com>
From: Aleksander Alekseev <aleksander@tigerdata.com>
To: pgsql-hackers@lists.postgresql.org
Cc: Evgeniy Gorbanev <gorbanyoves@basealt.ru>
Date: 2025-07-14T13:23:10Z
Lists: pgsql-hackers
Attachments
- v3-0001-Add-proper-checks-for-ecpg_strdup-return-value.patch (text/x-patch) patch v3-0001
Hi,
> Here is the corrected patch v3. Changes since v2:
>
> ```
> for (con = all_connections; con != NULL; con = con->next)
> {
> - /* XXX strcmp() will segfault if con->name is NULL */
> - if (strcmp(connection_name, con->name) == 0)
> + /* Check for NULL to prevent segfault */
> + if (con->name != NULL &&
> strcmp(connection_name, con->name) == 0)
> break;
> }
> ret = con;
> ```
>
> I was tired or something and didn't think of this trivial fix.
>
> As a side note it looks like ecpg could use some refactoring, but this
> is subject for another patch IMO.
Forgot the attachment. Sorry for the noise.
Commits
-
ecpg: Improve error detection around ecpg_strdup()
- a6eabec6808c 19 (unreleased) landed
-
ecpg: Fix NULL pointer dereference during connection lookup
- c934d5673894 13.22 landed
- 408fe659a890 14.19 landed
- 0123922f82d2 15.14 landed
- 313d3102facd 16.10 landed
- 2805e1c1edd5 17.6 landed
- 0ded7615d8ca 18.0 landed
- 1b8bbee05d70 19 (unreleased) landed