Hello,

While looking at another patch, I noticed the following code.

dt_common.c:2485:
> while (**pstr == ' ')
>   pstr++;

Since *pstr points to a single string, and the code later uses
"while (**pstr == ' ') (*pstr)++;", I think this was intended to skip
leading spaces, but actually advances the wrong pointer.

If this code were actually executed, it could cause a crash in the
worst case. However, the caller already skips leading spaces in
**pstr, so this is effectively dead code and probably hasn't caused
any problems.

I think the function itself needs to skip leading spaces to locate the
start of a token, so this part should be fixed as follows.

 while (**pstr == ' ')
-    pstr++;
+    (*pstr)++;

Regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
>From 96d1a68e552a36ffcb0f4c5f51cc2b8735edd6d6 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email protected]>
Date: Thu, 19 Nov 2026 16:11:37 +0900
Subject: [PATCH v1] Fix incorrect pointer increment in pgtypes_defmt_scan()

The function incorrectly increments pstr instead of *pstr when
skipping leading spaces. This bug has remained hidden because the
caller already skips leading spaces.
---
 src/interfaces/ecpg/pgtypeslib/dt_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 3ed5ad06c06..8c1f485f70c 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -2483,7 +2483,7 @@ pgtypes_defmt_scan(union un_fmt_comb *scan_val, int scan_type, char **pstr, char
 	char	   *strtol_end = NULL;
 
 	while (**pstr == ' ')
-		pstr++;
+		(*pstr)++;
 	pstr_end = find_end_token(*pstr, pfmt);
 	if (!pstr_end)
 	{
-- 
2.52.0

Reply via email to