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: Michael Paquier <michael(at)paquier(dot)xyz>, Evgeniy Gorbanev <gorbanyoves(at)basealt(dot)ru>
Subject: Re: Missing NULL check after calling ecpg_strdup
Date: 2025-07-21 08:48:27
Message-ID: CAJ7c6TMO9-aRrz80NbWQr-FFbTRTNh7WJkyWm=2NaXrV_y25uw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> OK, patch 0002 implements this idea with minimal changes to the existing logic.

Here is a slightly modified version:

``
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -570,7 +570,7 @@ AddStmtToCache(int lineno, /* line # of
statement */
entry = &stmtCacheEntries[entNo];
entry->lineno = lineno;
entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno, &alloc_failed);
- if (!entry->ecpgQuery)
+ if (alloc_failed)
return -1;
entry->connection = connection;
entry->execs = 0;
```

We know that ecpgQuery can't be NULL because we hash its value above.
Thus ecpg_strdup can fail only if strdup() fails.

Attachment Content-Type Size
v6-0002-Add-alloc_failed-argument-to-ecpg_strdup.patch text/x-patch 15.0 KB
v6-0001-Add-proper-checks-for-ecpg_strdup-return-value.patch text/x-patch 6.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-07-21 08:51:14 Re: Log prefix missing for subscriber log messages received from publisher
Previous Message vignesh C 2025-07-21 08:40:00 Re: Document slot's restart_lsn can go backward