| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Fix integer truncation in frontend pnstrdup() |
| Date: | 2026-10-20 07:40:27 |
| Message-ID: | 0E717E09-809F-4BC4-B3B1-36BE729DBFAE@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
While reading code during patch review, I noticed that the frontend pnstrdup() defined in fe_memutils.c uses an int len to store the string length returned by strnlen(). Since strnlen() returns a size_t, in theory this could cause integer truncation or signed overflow, though in practice it should be very unlikely to happen.
The backend pnstrdup() defined in mcxt.c doesn't have this problem. It keeps the string length in a Size.
The attached patch is a trivial fix for the frontend pnstrdup(), reusing the existing "Size size" variable to store the result of strnlen().
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-integer-truncation-in-frontend-pnstrdup.patch | application/octet-stream | 1.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Henson Choi | 2026-10-20 07:49:15 | [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan |
| Previous Message | Manu | 2026-10-20 07:37:55 | Re: Parallel Apply |