Re: Missing NULL check after calling ecpg_strdup

From: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Evgeniy Gorbanev <gorbanyoves(at)basealt(dot)ru>
Subject: Re: Missing NULL check after calling ecpg_strdup
Date: 2025-07-14 13:23:10
Message-ID: CAJ7c6TPh+ho1U72U0QgEVvLmnqokgy=OCo3Tk2rDNv-=Pa03hA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Attachment Content-Type Size
v3-0001-Add-proper-checks-for-ecpg_strdup-return-value.patch text/x-patch 6.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2025-07-14 13:27:13 Re: Make wal_receiver_timeout configurable per subscription
Previous Message Aleksander Alekseev 2025-07-14 13:22:09 Re: Missing NULL check after calling ecpg_strdup