Fix integer truncation in frontend pnstrdup()

Started by Chao Liabout 1 month ago2 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

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/

Attachments:

t254284_1
v1-0001-Fix-integer-truncation-in-frontend-pnstrdup.patchapplication/octet-stream; name=v1-0001-Fix-integer-truncation-in-frontend-pnstrdup.patch; x-unix-mode=0644Download+4-6
#2David Rowley
dgrowleyml@gmail.com
In reply to: Chao Li (#1)
Re: Fix integer truncation in frontend pnstrdup()

On Tue, 20 Oct 2026 at 20:41, Chao Li <li.evan.chao@gmail.com> wrote:

The attached patch is a trivial fix for the frontend pnstrdup(), reusing the existing "Size size" variable to store the result of strnlen().

I've pushed this to master only.

David