Fix inappropriate uses of PG_GETARG_UINT32()

Lists: pgsql-hackers
From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix inappropriate uses of PG_GETARG_UINT32()
Date: 2021-12-01 18:26:45
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

I noticed that the chr() function uses PG_GETARG_UINT32() to get its
argument, even though the argument is a (signed) int. So you get some
slightly silly behavior like this:

=> select chr(-333);
ERROR: 54000: requested character too large for encoding: -333

The attached patch fixes this by accepting the argument using
PG_GETARG_INT32(), doing some checks, and then casting it to unsigned
for the rest of the code.

The patch also fixes another inappropriate use in an example in the
documentation. These two were the only inappropriate uses I found,
after we had fixed a few recently.

Attachment Content-Type Size
0001-Fix-inappropriate-uses-of-PG_GETARG_UINT32.patch text/plain 3.6 KB

From: "Bossart, Nathan" <bossartn(at)amazon(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix inappropriate uses of PG_GETARG_UINT32()
Date: 2021-12-01 21:59:24
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 12/1/21, 10:29 AM, "Peter Eisentraut" <peter(dot)eisentraut(at)enterprisedb(dot)com> wrote:
> The attached patch fixes this by accepting the argument using
> PG_GETARG_INT32(), doing some checks, and then casting it to unsigned
> for the rest of the code.
>
> The patch also fixes another inappropriate use in an example in the
> documentation. These two were the only inappropriate uses I found,
> after we had fixed a few recently.

LGTM

Nathan


From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: "Bossart, Nathan" <bossartn(at)amazon(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix inappropriate uses of PG_GETARG_UINT32()
Date: 2021-12-06 12:47:35
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On 01.12.21 22:59, Bossart, Nathan wrote:
> On 12/1/21, 10:29 AM, "Peter Eisentraut" <peter(dot)eisentraut(at)enterprisedb(dot)com> wrote:
>> The attached patch fixes this by accepting the argument using
>> PG_GETARG_INT32(), doing some checks, and then casting it to unsigned
>> for the rest of the code.
>>
>> The patch also fixes another inappropriate use in an example in the
>> documentation. These two were the only inappropriate uses I found,
>> after we had fixed a few recently.
>
> LGTM

committed