| From: | Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Fix PGTYPESdate_fmt_asc overflow when a year does not fit "yyyy" |
| Date: | 2026-08-17 18:41:05 |
| Message-ID: | CAB8bMiuFyCb+X7oLq8nm3nR9xLCiJLcE502yX9j_tfrkYAAPsw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
вт, 11 авг. 2026 г. в 19:31, Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>:
> Hi, Hackers!
>
> PGTYPESdate_fmt_asc() replaces fixed-width tokens in place. "yyyy"
> is four characters. Callers typically size outbuf as
> strlen(fmtstring)+1, as dt_test does.
>
> For year >= 10000, "%04u" produces five or more digits. memcpy()
> over the "yyyy" span overruns that token and clobbers the trailing
> NUL in a strlen(fmt)+1 buffer. ASan reports a heap-buffer-overflow
> on the next strstr() in the token loop.
> ```
> const char *fmt = "yyyy";
> date d = PGTYPESdate_from_asc("10000-01-01", NULL);
> char *out = malloc(strlen(fmt) + 1);
>
> PGTYPESdate_fmt_asc(d, fmt, out);
> ```
> The attached patch rejects a replacement longer than the token and
> sets errno to PGTYPES_DATE_BAD_DATE. A dt_test case is included.
>
> Hi, All!
Maybe someone will have some free time to do a review. Thanks a lot in
advance.
--
Regards,
Rachitskiy Andrey
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Dunstan | 2026-08-17 18:44:26 | Re: Residual cleanups for tied objects in PL/Perl |
| Previous Message | Andrey Rachitskiy | 2026-08-17 18:25:41 | Re: Residual cleanups for tied objects in PL/Perl |