Detect buffer underflow in get_th() - Mailing list pgsql-hackers

From Alexander Kuznetsov
Subject Detect buffer underflow in get_th()
Date
Msg-id e22df993-cdb4-4d0a-b629-42211ebed582@altlinux.org
Whole thread Raw
Responses Re: Detect buffer underflow in get_th()
List pgsql-hackers
Hello everyone,

In src/backend/utils/adt/formatting.c:1516, there is a get_th() function utilized to return ST/ND/RD/TH suffixes for
simplenumbers.
 
Upon reviewing its behavior, it appears capable of receiving non-numeric inputs (this is verified by a check at
formatting.c:1527).

Given that the function can accept non-numeric inputs,
it is plausible that it could also receive an empty input,
although a brief examination of its calls did not reveal any such instances.

Nevertheless, if the function were to receive an empty input of zero length,
a buffer underflow would occur when attempting to compute *(num + (len - 1)), as (len - 1) would result in a negative
shift.
To mitigate this issue, I propose a patch incorporating the zero_length_character_string error code, as detailed in the
attachment.

-- 
Best regards,
Alexander Kuznetsov
Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Slow catchup of 2PC (twophase) transactions on replica in LR
Next
From: David Rowley
Date:
Subject: Re: Parent/child context relation in pg_get_backend_memory_contexts()