Skip to content

Commit 72665f3

Browse files
committed
tests: parser: Add test cases for too long cases
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 27893b3 commit 72665f3

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

tests/internal/parser.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include <time.h>
1111
#include <string.h>
12+
#include <math.h>
13+
#include <float.h>
14+
#include <limits.h>
1215
#include "flb_tests_internal.h"
1316

1417
/* Parsers configuration */
@@ -588,13 +591,73 @@ void test_parser_time_system_timezone_midnight()
588591
flb_config_exit(config);
589592
}
590593

594+
void test_parser_time_lookup_long_fraction()
595+
{
596+
int ret;
597+
double ns;
598+
time_t epoch;
599+
struct flb_tm tm;
600+
struct flb_parser *parser;
601+
struct flb_config *config;
602+
const char *time_string = "10/03/2016 12:21:08.123456789123456789123456789123456789123456789123456789";
603+
604+
config = flb_config_init();
605+
load_json_parsers(config);
606+
607+
parser = flb_parser_get("generic_N", config);
608+
TEST_CHECK(parser != NULL);
609+
if (parser == NULL) {
610+
flb_parser_exit(config);
611+
flb_config_exit(config);
612+
return;
613+
}
614+
615+
ret = flb_parser_time_lookup(time_string, strlen(time_string), 0, parser, &tm, &ns);
616+
TEST_CHECK(ret == 0);
617+
618+
epoch = flb_parser_tm2time(&tm, FLB_FALSE);
619+
TEST_CHECK(epoch == 1475497268);
620+
TEST_CHECK(fabs(ns - 0.123456789) <= DBL_EPSILON);
621+
622+
flb_parser_exit(config);
623+
flb_config_exit(config);
624+
}
625+
626+
void test_parser_time_lookup_reject_oversized_length()
627+
{
628+
int ret;
629+
double ns;
630+
struct flb_tm tm;
631+
struct flb_parser *parser;
632+
struct flb_config *config;
633+
634+
config = flb_config_init();
635+
load_json_parsers(config);
636+
637+
parser = flb_parser_get("generic_N", config);
638+
TEST_CHECK(parser != NULL);
639+
if (parser == NULL) {
640+
flb_parser_exit(config);
641+
flb_config_exit(config);
642+
return;
643+
}
644+
645+
ret = flb_parser_time_lookup("x", (size_t) INT_MAX + 1, 0, parser, &tm, &ns);
646+
TEST_CHECK(ret == -1);
647+
648+
flb_parser_exit(config);
649+
flb_config_exit(config);
650+
}
651+
591652

592653
TEST_LIST = {
593654
{ "tzone_offset", test_parser_tzone_offset},
594655
{ "time_lookup", test_parser_time_lookup},
595656
{ "json_time_lookup", test_json_parser_time_lookup},
596657
{ "regex_time_lookup", test_regex_parser_time_lookup},
597658
{ "time_system_timezone_midnight", test_parser_time_system_timezone_midnight},
659+
{ "time_lookup_long_fraction", test_parser_time_lookup_long_fraction},
660+
{ "time_lookup_reject_oversized_length", test_parser_time_lookup_reject_oversized_length},
598661
{ "mysql_unquoted" , test_mysql_unquoted },
599662
{ 0 }
600663
};

0 commit comments

Comments
 (0)