Re: glibc qsort() vulnerability - Mailing list pgsql-hackers

From Mats Kindahl
Subject Re: glibc qsort() vulnerability
Date
Msg-id CA+14425kn0RxC62M7ZaD5BRzBJEPRRLQQB4DGdL+=vxHS1E81Q@mail.gmail.com
Whole thread Raw
In response to Re: glibc qsort() vulnerability  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: glibc qsort() vulnerability
List pgsql-hackers
On Fri, Feb 9, 2024 at 9:08 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Fri, Feb 09, 2024 at 08:43:21PM +0100, Mats Kindahl wrote:
> QQ: right now it looks like this:
>
> static inline int
> pg_cmp_u16(uint16 a, uint16 b)
> {
>
> return (int32)a - (int32)b;
>
> }
>
>
> and
>
> static inline int
> pg_cmp_u32(uint32 a, uint32 b)
> {
>
> return (a > b) - (a < b);
>
> }
>
>
> I think that is clear enough, but do you want more casts added for the
> return value as well?

I think that is reasonably clear.  The latter does require you to know that
< and > return (int) 0 or (int) 1, which might be worth a short comment.
But that's just nitpicking...


Hi all,

Split the code into two patches: one that just adds the functions (including the new pg_cmp_size()) to common/int.h and one that starts using them. I picked the name "pg_cmp_size" rather than "pg_cmp_size_t" since "_t" is usually used as a suffix for types.

I added a comment to the (a > b) - (a < b) return and have also added casts to (int32) for the int16 and uint16 functions (we need a signed int for uin16 since we need to be able to get a negative number).

Changed the type of two instances that had an implicit cast from size_t to int and used the new pg_,cmp_size() function.

Also fixed the missed replacements in the "contrib" directory.

Best wishes,
Mats Kindahl
  
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: backend *.c #include cleanup (IWYU)
Next
From: "Zhijie Hou (Fujitsu)"
Date:
Subject: RE: Synchronizing slots from primary to standby