提交 3ce28c06 编写于 作者: G Ganlin Zhao

[TD-5505]<fix>: return error if there're additional illegal characters

after timezeone str
上级 83b5c2a6
...@@ -72,12 +72,12 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, ...@@ -72,12 +72,12 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0,
// ==== mktime() kernel code =================// // ==== mktime() kernel code =================//
static int64_t m_deltaUtc = 0; static int64_t m_deltaUtc = 0;
void deltaToUtcInitOnce() { void deltaToUtcInitOnce() {
struct tm tm = {0}; struct tm tm = {0};
(void)strptime("1970-01-01 00:00:00", (const char *)("%Y-%m-%d %H:%M:%S"), &tm); (void)strptime("1970-01-01 00:00:00", (const char *)("%Y-%m-%d %H:%M:%S"), &tm);
m_deltaUtc = (int64_t)mktime(&tm); m_deltaUtc = (int64_t)mktime(&tm);
//printf("====delta:%lld\n\n", seconds); //printf("====delta:%lld\n\n", seconds);
return; return;
} }
...@@ -90,7 +90,7 @@ static char* forwardToTimeStringEnd(char* str); ...@@ -90,7 +90,7 @@ static char* forwardToTimeStringEnd(char* str);
static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = {
parseLocaltime, parseLocaltime,
parseLocaltimeWithDst parseLocaltimeWithDst
}; };
int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
...@@ -194,6 +194,13 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { ...@@ -194,6 +194,13 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
i += 2; i += 2;
} }
//return error if there're illegal charaters after min(2 Digits)
char *minStr = &str[i];
if (minStr[1] != '\0' && minStr[2] != '\0') {
return -1;
}
int64_t minute = strnatoi(&str[i], 2); int64_t minute = strnatoi(&str[i], 2);
if (minute > 59) { if (minute > 59) {
return -1; return -1;
...@@ -252,7 +259,7 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del ...@@ -252,7 +259,7 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del
int64_t fraction = 0; int64_t fraction = 0;
str = forwardToTimeStringEnd(timestr); str = forwardToTimeStringEnd(timestr);
if (str[0] == 'Z' || str[0] == 'z') { if ((str[0] == 'Z' || str[0] == 'z') && str[1] == '\0') {
/* utc time, no millisecond, return directly*/ /* utc time, no millisecond, return directly*/
*time = seconds * factor; *time = seconds * factor;
} else if (str[0] == '.') { } else if (str[0] == '.') {
...@@ -266,6 +273,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del ...@@ -266,6 +273,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del
char seg = str[0]; char seg = str[0];
if (seg != 'Z' && seg != 'z' && seg != '+' && seg != '-') { if (seg != 'Z' && seg != 'z' && seg != '+' && seg != '-') {
return -1; return -1;
} else if ((seg == 'Z' || seg == 'z') && str[1] != '\0') {
return -1;
} else if (seg == '+' || seg == '-') { } else if (seg == '+' || seg == '-') {
// parse the timezone // parse the timezone
if (parseTimezone(str, &tzOffset) == -1) { if (parseTimezone(str, &tzOffset) == -1) {
......
...@@ -462,6 +462,42 @@ TEST(testCase, parse_time) { ...@@ -462,6 +462,42 @@ TEST(testCase, parse_time) {
char t23[] = "2017-12-31T9:0:0.1+13:1"; char t23[] = "2017-12-31T9:0:0.1+13:1";
EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI, 0), 0); EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI, 0), 0);
char t24[] = "2017-12-31T9:0:0.1+13:001";
EXPECT_EQ(taosParseTime(t24, &time, strlen(t24), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t25[] = "2017-12-31T9:0:0.1+13:00abc";
EXPECT_EQ(taosParseTime(t25, &time, strlen(t25), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t26[] = "2017-12-31T9:0:0.1+13001";
EXPECT_EQ(taosParseTime(t26, &time, strlen(t26), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t27[] = "2017-12-31T9:0:0.1+1300abc";
EXPECT_EQ(taosParseTime(t27, &time, strlen(t27), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t28[] = "2017-12-31T9:0:0Z+12:00";
EXPECT_EQ(taosParseTime(t28, &time, strlen(t28), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t29[] = "2017-12-31T9:0:0.123Z+12:00";
EXPECT_EQ(taosParseTime(t29, &time, strlen(t29), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t65[] = "2017-12-31 9:0:0.1+13:001";
EXPECT_EQ(taosParseTime(t65, &time, strlen(t65), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t66[] = "2017-12-31 9:0:0.1+13:00abc";
EXPECT_EQ(taosParseTime(t66, &time, strlen(t66), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t67[] = "2017-12-31 9:0:0.1+13001";
EXPECT_EQ(taosParseTime(t67, &time, strlen(t67), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t68[] = "2017-12-31 9:0:0.1+1300abc";
EXPECT_EQ(taosParseTime(t68, &time, strlen(t68), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t69[] = "2017-12-31 9:0:0Z+12:00";
EXPECT_EQ(taosParseTime(t69, &time, strlen(t69), TSDB_TIME_PRECISION_MILLI, 0), -1);
char t70[] = "2017-12-31 9:0:0.123Z+12:00";
EXPECT_EQ(taosParseTime(t70, &time, strlen(t70), TSDB_TIME_PRECISION_MILLI, 0), -1);
} }
TEST(testCase, tvariant_convert) { TEST(testCase, tvariant_convert) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册