Fix inappropriate uses of PG_GETARG_UINT32()

Started by Peter Eisentrautover 4 years ago3 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

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.

Attachments:

0001-Fix-inappropriate-uses-of-PG_GETARG_UINT32.patchtext/plain; charset=UTF-8; name=0001-Fix-inappropriate-uses-of-PG_GETARG_UINT32.patchDownload+21-15
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Peter Eisentraut (#1)
Re: Fix inappropriate uses of PG_GETARG_UINT32()

On 12/1/21, 10:29 AM, "Peter Eisentraut" <peter.eisentraut@enterprisedb.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

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Nathan Bossart (#2)
Re: Fix inappropriate uses of PG_GETARG_UINT32()

On 01.12.21 22:59, Bossart, Nathan wrote:

On 12/1/21, 10:29 AM, "Peter Eisentraut" <peter.eisentraut@enterprisedb.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