summaryrefslogtreecommitdiffstats
path: root/mbbsd/stuff.c
diff options
context:
space:
mode:
authormhsin <mhsin@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-18 17:36:52 +0800
committermhsin <mhsin@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-18 17:36:52 +0800
commitdc334d60b27f9a99cea1926a0b74e899c42f9487 (patch)
treecf75f592f47cabd04a17e4d0ff02a7d4e218c683 /mbbsd/stuff.c
parent7deddbaf74047db0e64d07a0798c71592e8aa8d5 (diff)
downloadpttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar.gz
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar.bz2
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar.lz
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar.xz
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.tar.zst
pttbbs-dc334d60b27f9a99cea1926a0b74e899c42f9487.zip
Revert r3704 and add saturation check for gettime().
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3705 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/stuff.c')
-rw-r--r--mbbsd/stuff.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 9d08e2d2..90c0988a 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -216,6 +216,7 @@ gettime(int line, time4_t dt, const char*head)
char yn[7];
int i;
struct tm *ptime = localtime4(&dt), endtime;
+ time_t t;
memcpy(&endtime, ptime, sizeof(struct tm));
snprintf(yn, sizeof(yn), "%4d", ptime->tm_year + 1900);
@@ -223,13 +224,7 @@ gettime(int line, time4_t dt, const char*head)
i=strlen(head);
do {
getdata_buf(line, i, " 西元年:", yn, 5, LCECHO);
- } while ((endtime.tm_year = atoi(yn) - 1970) < 0 || endtime.tm_year > 200);
-
- // current time4_t is signed.
- // safe range: 2038(signed)~1970(unsigned)
- if (endtime.tm_year > 137) endtime.tm_year = 137;
- if (endtime.tm_year < 70) endtime.tm_year = 70;
-
+ } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200);
snprintf(yn, sizeof(yn), "%d", ptime->tm_mon + 1);
do {
getdata_buf(line, i+15, "月:", yn, 3, LCECHO);
@@ -242,7 +237,13 @@ gettime(int line, time4_t dt, const char*head)
do {
getdata_buf(line, i+33, "時(0-23):", yn, 3, LCECHO);
} while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23);
- return mktime(&endtime);
+ t = mktime(&endtime);
+ /* saturation check */
+ if(t < 0)
+ t = 1;
+ if(t > INT_MAX)
+ t = INT_MAX;
+ return t;
}
// synchronize 'now'