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

Commit2e82d0b

Browse files
committed
Prevent datebsearch() from crashing on base == NULL && nel == 0.
Normally nel == 0 works okay because the initial value of "last" will beless than "base"; but if "base" is zero then the calculation wraps aroundand we have a very large (unsigned) value for "last", so that the loop canbe entered and we get a SIGSEGV on a bogus pointer.This is certainly the proximate cause of the recent reports of Windowsbuilds crashing on 'infinity'::timestamp --- evidently, they're either notsetting an active timezonetktbl, or setting an empty one. It's not yetclear to me why it's only happening on Windows and not happening on anybuildfarm member. But even if that's due to some bug elsewhere, it seemswise for this function to not choke on the powerup values oftimezonetktbl/sztimezonetktbl.I also changed the copy of this code in ecpglib, although I am not surewhether it's exposed to a similar hazard.Per report and stack trace from Richard Broersma.
1 parent7ff7711 commit2e82d0b

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,24 +3569,27 @@ DateTimeParseError(int dterr, const char *str, const char *datatype)
35693569
staticconstdatetkn*
35703570
datebsearch(constchar*key,constdatetkn*base,intnel)
35713571
{
3572-
constdatetkn*last=base+nel-1,
3573-
*position;
3574-
intresult;
3575-
3576-
while (last >=base)
3572+
if (nel>0)
35773573
{
3578-
position=base+ ((last-base) >>1);
3579-
result=key[0]-position->token[0];
3580-
if (result==0)
3574+
constdatetkn*last=base+nel-1,
3575+
*position;
3576+
intresult;
3577+
3578+
while (last >=base)
35813579
{
3582-
result=strncmp(key,position->token,TOKMAXLEN);
3580+
position=base+ ((last-base) >>1);
3581+
result=key[0]-position->token[0];
35833582
if (result==0)
3584-
returnposition;
3583+
{
3584+
result=strncmp(key,position->token,TOKMAXLEN);
3585+
if (result==0)
3586+
returnposition;
3587+
}
3588+
if (result<0)
3589+
last=position-1;
3590+
else
3591+
base=position+1;
35853592
}
3586-
if (result<0)
3587-
last=position-1;
3588-
else
3589-
base=position+1;
35903593
}
35913594
returnNULL;
35923595
}

‎src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,24 +512,27 @@ char *pgtypes_date_months[] = {"January", "February", "March", "April", "May"
512512
staticdatetkn*
513513
datebsearch(char*key,datetkn*base,unsignedintnel)
514514
{
515-
datetkn*last=base+nel-1,
516-
*position;
517-
intresult;
518-
519-
while (last >=base)
515+
if (nel>0)
520516
{
521-
position=base+ ((last-base) >>1);
522-
result=key[0]-position->token[0];
523-
if (result==0)
517+
datetkn*last=base+nel-1,
518+
*position;
519+
intresult;
520+
521+
while (last >=base)
524522
{
525-
result=strncmp(key,position->token,TOKMAXLEN);
523+
position=base+ ((last-base) >>1);
524+
result=key[0]-position->token[0];
526525
if (result==0)
527-
returnposition;
526+
{
527+
result=strncmp(key,position->token,TOKMAXLEN);
528+
if (result==0)
529+
returnposition;
530+
}
531+
if (result<0)
532+
last=position-1;
533+
else
534+
base=position+1;
528535
}
529-
if (result<0)
530-
last=position-1;
531-
else
532-
base=position+1;
533536
}
534537
returnNULL;
535538
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp