| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: A latent pointer increment bug in pgtypes_defmt_scan() |
| Date: | 2026-11-19 08:33:01 |
| Message-ID: | D46FF166-96D3-4DB9-9C4D-DA4CF35ABD30@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Nov 19, 2026, at 15:22, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote:
>
> Hello,
>
> While looking at another patch, I noticed the following code.
>
> dt_common.c:2485:
>> while (**pstr == ' ')
>> pstr++;
>
Good catch. This seems like a typical pointer mistake made in a C class.
> 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 so. The only caller PGTYPEStimestamp_defmt_scan() has already skipped all leading spaces.
>
> 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
> <v1-0001-Fix-incorrect-pointer-increment-in-pgtypes_defmt_.patch>
The fix looks correct to me.
But maybe we can just remove the loop and add an assertion to ensure that str has no leading spaces?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rushabh Lathia | 2026-11-19 08:49:23 | Re: ORDER BY ALL |
| Previous Message | Chao Li | 2026-11-19 08:16:19 | Re: Block various aggregate component functions from being called directly |