Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8692f66

Browse files
committed
Fix thinko introduced in6b423ec
As pointed out by Dean Rasheed, we really should be using tmp >-(PG_INTNN_MIN / 10) rather than tmp > (PG_INTNN_MAX / 10) for checkingfor overflows in the accumulation in the pg_strtointNN functions. Thisdoes happen to be the same number when dividing by 10, but there is apending patch which adds other bases and this is not the same number if wewere to divide by 2 rather than 10, for example. If the base 2 parsingwas to follow this example then we could accidentally think a stringcontaining the value of PG_INT32_MIN was an overflow in pg_strtoint32.Clearly that shouldn't overflow.This does not fix any actual live bugs, only some bad examples of overflowchecks for future bases.Reported-by: Dean RasheedDiscussion:https://postgr.es/m/CAEZATCVEtwfhdm-K-etZYFB0=qsR0nT6qXta_W+GQx4RYph1dg@mail.gmail.com
1 parentd94f32d commit8692f66

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎src/backend/utils/adt/numutils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pg_strtoint16(const char *s)
122122
/* process digits */
123123
while (*ptr&&isdigit((unsignedchar)*ptr))
124124
{
125-
if (unlikely(tmp>(PG_INT16_MAX /10)))
125+
if (unlikely(tmp>-(PG_INT16_MIN /10)))
126126
gotoout_of_range;
127127

128128
tmp=tmp*10+ (*ptr++-'0');
@@ -200,7 +200,7 @@ pg_strtoint32(const char *s)
200200
/* process digits */
201201
while (*ptr&&isdigit((unsignedchar)*ptr))
202202
{
203-
if (unlikely(tmp>(PG_INT32_MAX /10)))
203+
if (unlikely(tmp>-(PG_INT32_MIN /10)))
204204
gotoout_of_range;
205205

206206
tmp=tmp*10+ (*ptr++-'0');
@@ -278,7 +278,7 @@ pg_strtoint64(const char *s)
278278
/* process digits */
279279
while (*ptr&&isdigit((unsignedchar)*ptr))
280280
{
281-
if (unlikely(tmp>(PG_INT64_MAX /10)))
281+
if (unlikely(tmp>-(PG_INT64_MIN /10)))
282282
gotoout_of_range;
283283

284284
tmp=tmp*10+ (*ptr++-'0');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp