Fix PGTYPESdate_fmt_asc overflow when a year does not fit "yyyy"
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.
--
Regards,
Rachitskiy Andrey
вт, 11 авг. 2026 г. в 19:31, Andrey Rachitskiy <pl0h0yp1@gmail.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
Hello!
-[NO_PID]: ECPGtrans on line 393: action "rollback"; connection "ecpg1_regression"
+[NO_PID]: ECPGtrans on line 412: action "rollback"; connection "ecpg1_regression"
The modified test is failing in my run, it seems this should be 409?
чт, 20 авг. 2026 г. в 03:17, Zsolt Parragi <zsolt.parragi@percona.com>:
Hello!
-[NO_PID]: ECPGtrans on line 393: action "rollback"; connection "ecpg1_regression" +[NO_PID]: ECPGtrans on line 412: action "rollback"; connection "ecpg1_regression"The modified test is failing in my run, it seems this should be 409?
Dear Zsolt,
Thanks for the review.
After shortening the test comment I updated the expected .c #line
markers but forgot the matching stderr line number. Fixed in the
attached v2.
--
Regards,
Rachitskiy Andrey
чт, 20 авг. 2026 г. в 12:06, Andrey Rachitskiy <pl0h0yp1@gmail.com>:
чт, 20 авг. 2026 г. в 03:17, Zsolt Parragi <zsolt.parragi@percona.com>:
Hello!
-[NO_PID]: ECPGtrans on line 393: action "rollback"; connection "ecpg1_regression" +[NO_PID]: ECPGtrans on line 412: action "rollback"; connection "ecpg1_regression"The modified test is failing in my run, it seems this should be 409?
Dear Zsolt,
Thanks for the review.
After shortening the test comment I updated the expected .c #line
markers but forgot the matching stderr line number. Fixed in the
attached v2.
Hello everybody!
Reminder on this patch.
Have a good end of the week and enjoy the weekend.
--
Regards,
Rachitskiy Andrey
пт, 4 сент. 2026 г. в 10:01, Andrey Rachitskiy <pl0h0yp1@gmail.com>:
чт, 20 авг. 2026 г. в 12:06, Andrey Rachitskiy <pl0h0yp1@gmail.com>:
чт, 20 авг. 2026 г. в 03:17, Zsolt Parragi <zsolt.parragi@percona.com>:
Hello!
-[NO_PID]: ECPGtrans on line 393: action "rollback"; connection "ecpg1_regression" +[NO_PID]: ECPGtrans on line 412: action "rollback"; connection "ecpg1_regression"The modified test is failing in my run, it seems this should be 409?
Dear Zsolt,
Thanks for the review.
After shortening the test comment I updated the expected .c #line
markers but forgot the matching stderr line number. Fixed in the
attached v2.Hello everybody!
Reminder on this patch.
Have a good end of the week and enjoy the weekend.
Hello everybody!
Reminder on this patch :)
--
Regards,
Rachitskiy Andrey
On Thu, 8 Oct 2026 at 21:03, Andrey Rachitskiy <pl0h0yp1@gmail.com> wrote:
Reminder on this patch :)
Please do not send reminders. It is not a scalable thing to do. The
commitfest application is meant to serve the purpose of not forgetting
patches. Please use it.
David