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

Commit649a125

Browse files
author
Michael Meskes
committed
Added result checks for calls to gmtime().
1 parent08ffa78 commit649a125

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.34 2007/11/15 21:14:45 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.35 2009/02/04 08:51:09 meskes Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -87,7 +87,11 @@ PGTYPESdate_from_asc(char *str, char **endptr)
8787
break;
8888

8989
caseDTK_EPOCH:
90-
GetEpochTime(tm);
90+
if (GetEpochTime(tm)<0)
91+
{
92+
errno=PGTYPES_DATE_BAD_DATE;
93+
returnINT_MIN;
94+
}
9195
break;
9296

9397
default:
@@ -153,7 +157,8 @@ PGTYPESdate_today(date * d)
153157
structtmts;
154158

155159
GetCurrentDateTime(&ts);
156-
*d=date2j(ts.tm_year,ts.tm_mon,ts.tm_mday)-date2j(2000,1,1);
160+
if (errno==0)
161+
*d=date2j(ts.tm_year,ts.tm_mon,ts.tm_mday)-date2j(2000,1,1);
157162
return;
158163
}
159164

‎src/interfaces/ecpg/pgtypeslib/dt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.40 2008/11/26 16:31:02 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.41 2009/02/04 08:51:09 meskes Exp $ */
22

33
#ifndefDT_H
44
#defineDT_H
@@ -342,7 +342,7 @@ inttm2timestamp(struct tm *, fsec_t, int *, timestamp *);
342342
intDecodeUnits(intfield,char*lowtoken,int*val);
343343
boolCheckDateTokenTables(void);
344344
intEncodeDateOnly(structtm*,int,char*,bool);
345-
voidGetEpochTime(structtm*);
345+
intGetEpochTime(structtm*);
346346
intParseDateTime(char*,char*,char**,int*,int,int*,char**);
347347
intDecodeDateTime(char**,int*,int,int*,structtm*,fsec_t*,bool);
348348
voidj2date(int,int*,int*,int*);

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.45 2009/02/02 15:35:28 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.46 2009/02/04 08:51:09 meskes Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -982,22 +982,27 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
982982
return TRUE;
983983
}/* EncodeDateTime() */
984984

985-
void
985+
int
986986
GetEpochTime(structtm*tm)
987987
{
988988
structtm*t0;
989989
time_tepoch=0;
990990

991991
t0=gmtime(&epoch);
992992

993-
tm->tm_year=t0->tm_year+1900;
994-
tm->tm_mon=t0->tm_mon+1;
995-
tm->tm_mday=t0->tm_mday;
996-
tm->tm_hour=t0->tm_hour;
997-
tm->tm_min=t0->tm_min;
998-
tm->tm_sec=t0->tm_sec;
993+
if (t0)
994+
{
995+
tm->tm_year=t0->tm_year+1900;
996+
tm->tm_mon=t0->tm_mon+1;
997+
tm->tm_mday=t0->tm_mday;
998+
tm->tm_hour=t0->tm_hour;
999+
tm->tm_min=t0->tm_min;
1000+
tm->tm_sec=t0->tm_sec;
1001+
1002+
return0;
1003+
}
9991004

1000-
return;
1005+
return-1;
10011006
}/* GetEpochTime() */
10021007

10031008
staticvoid
@@ -1006,11 +1011,18 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
10061011
time_ttime= (time_t)_time;
10071012
structtm*tx;
10081013

1014+
errno=0;
10091015
if (tzp!=NULL)
10101016
tx=localtime((time_t*)&time);
10111017
else
10121018
tx=gmtime((time_t*)&time);
10131019

1020+
if (!tx)
1021+
{
1022+
errno=PGTYPES_TS_BAD_TIMESTAMP;
1023+
return;
1024+
}
1025+
10141026
tm->tm_year=tx->tm_year+1900;
10151027
tm->tm_mon=tx->tm_mon+1;
10161028
tm->tm_mday=tx->tm_mday;
@@ -2852,12 +2864,18 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
28522864
time_tet= (time_t)scan_val.luint_val;
28532865

28542866
tms=gmtime(&et);
2855-
*year=tms->tm_year+1900;
2856-
*month=tms->tm_mon+1;
2857-
*day=tms->tm_mday;
2858-
*hour=tms->tm_hour;
2859-
*minute=tms->tm_min;
2860-
*second=tms->tm_sec;
2867+
2868+
if (tms)
2869+
{
2870+
*year=tms->tm_year+1900;
2871+
*month=tms->tm_mon+1;
2872+
*day=tms->tm_mday;
2873+
*hour=tms->tm_hour;
2874+
*minute=tms->tm_min;
2875+
*second=tms->tm_sec;
2876+
}
2877+
else
2878+
err=1;
28612879
}
28622880
break;
28632881
case'S':

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.42 2008/05/17 01:28:25 adunstan Exp $
2+
* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.43 2009/02/04 08:51:10 meskes Exp $
33
*/
44
#include"postgres_fe.h"
55

@@ -91,11 +91,18 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
9191
statictimestamp
9292
SetEpochTimestamp(void)
9393
{
94+
#ifdefHAVE_INT64_TIMESTAMP
95+
int64noresult=0;
96+
#else
97+
doublenoresult=0.0;
98+
#endif
9499
timestampdt;
95100
structtmtt,
96101
*tm=&tt;
97102

98-
GetEpochTime(tm);
103+
if (GetEpochTime(tm)<0)
104+
returnnoresult;
105+
99106
tm2timestamp(tm,0,NULL,&dt);
100107
returndt;
101108
}/* SetEpochTimestamp() */
@@ -372,7 +379,8 @@ PGTYPEStimestamp_current(timestamp * ts)
372379
structtmtm;
373380

374381
GetCurrentDateTime(&tm);
375-
tm2timestamp(&tm,0,NULL,ts);
382+
if (errno==0)
383+
tm2timestamp(&tm,0,NULL,ts);
376384
return;
377385
}
378386

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp