From 6a95dff36aec7ebd83af47ba74de5d22fe13da9f Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Thu, 13 Oct 2022 16:46:16 +0100 Subject: regression: avoid SIGSEGV in test_timezone_from_builtin() When builtin timezones are not enabled 'regression' test SIGSEGVs due to strdup(NULL) in test_timezone_from_builtin(): ================================================================= ==6477==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7ffff7a1aae6 bp 0x7fffffffb6c0 sp 0x7fffffffae68 T0) ==6477==The signal is caused by a READ memory access. ==6477==Hint: address points to the zero page. #0 0x7ffff7a1aae6 in __sanitizer::internal_strlen(char const*) (...gcc-13.0.0-lib/lib/libasan.so.8+0xebae6) #1 0x7ffff79aceb0 in __interceptor_strdup (...gcc-13.0.0-lib/lib/libasan.so.8+0x7deb0) #2 0x41db71 in test_timezone_from_builtin /build/libical/src/test/regression.c:4682 #3 0x42beff in test_run /build/libical/src/test/regression-utils.c:236 #4 0x40b962 in main /build/libical/src/test/regression.c:5475 #5 0x7ffff6d2858d in __libc_start_call_main (...glibc-2.35-163/lib/libc.so.6+0x2958d) #6 0x7ffff6d28648 in __libc_start_main_impl (...glibc-2.35-163/lib/libc.so.6+0x29648) #7 0x40bc84 in _start (/build/libical/build/src/test/regression+0x40bc84) AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (...gcc-13.0.0-lib/lib/libasan.so.8+0xebae6) in __sanitizer::internal_strlen(char const*) The change disables the test if builtin zimezone tables are not enabled. --- src/test/regression.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/test/regression.c b/src/test/regression.c index 36a49961..0d40f028 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -4416,6 +4416,10 @@ void test_timezone_from_builtin(void) char *strcomp, *tzidprefix, *prevslash = NULL, *prevprevslash = NULL, *p; size_t len; + /* Builtins are not enabled, zone loading will fail. */ + if (!icaltimezone_get_builtin_tzdata()) + return; + zone = icaltimezone_get_builtin_timezone("America/New_York"); tzidprefix = strdup(icaltimezone_get_tzid (zone)); p = tzidprefix; -- cgit v1.2.1 From f9b2c34a551d461d065bf868e218f3df560be93f Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Thu, 13 Oct 2022 20:08:42 +0100 Subject: regression-cxx.cpp: fix test by explicitly setting errno When embedded timezone data is not enabled errors from previous tests set icalerrno to non-default and cause exception handling to throw wrong exception: not ok 1186 - Testing exception handling # test failed: "" # at: /build/libical/src/test/regression-cxx.cpp:170 # got: 0 # expected: 1 The change explicitly drops icalerrno to isolate the test result from other tests. --- src/test/regression-cxx.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/test/regression-cxx.cpp b/src/test/regression-cxx.cpp index 6bb33b3a..2fbe3ae6 100644 --- a/src/test/regression-cxx.cpp +++ b/src/test/regression-cxx.cpp @@ -167,6 +167,7 @@ void test_cxx(void) int caughtException = 0; try { + icalerrno = ICAL_NO_ERROR; VComponent v = VComponent(string("HFHFHFHF")); } catch (icalerrorenum err) { if (err == ICAL_BADARG_ERROR) { -- cgit v1.2.1 From 7d701ff5ba1425895ac138be6ec0a177ec26c1ce Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 26 Oct 2022 17:45:42 +0200 Subject: misc: Update sources to more modern C The code fails to build when having enabled (gcc) warnings: -Werror=implicit -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition -Werror=strict-prototypes --- src/libical-glib/tools/generator.c | 2 +- src/libical-glib/tools/xml-parser.c | 12 ++-- src/libical-glib/tools/xml-parser.h | 12 ++-- src/libical/caldate.c | 6 +- src/libical/icalduration.c | 2 +- src/libical/icalerror.c | 4 +- src/libical/icalmemory.c | 2 +- src/libical/pvl.c | 2 +- src/libicalss/icalsslexer.c | 2 +- src/libicalvcal/vcc.c | 36 ++++++------ src/libicalvcal/vobject.c | 2 +- src/libicalvcal/vobject.h | 2 +- src/test/builtin_timezones.c | 2 +- src/test/icaltm_test.c | 5 +- src/test/regression-component.c | 6 +- src/test/regression-recur.c | 2 +- src/test/regression-storage.c | 2 +- src/test/regression.c | 106 ++++++++++++++++++------------------ src/test/regression.h | 2 +- src/test/timezones.c | 2 +- 20 files changed, 105 insertions(+), 106 deletions(-) (limited to 'src') diff --git a/src/libical-glib/tools/generator.c b/src/libical-glib/tools/generator.c index 694c5fd0..f178ec9d 100644 --- a/src/libical-glib/tools/generator.c +++ b/src/libical-glib/tools/generator.c @@ -1921,7 +1921,7 @@ gchar *get_true_type(const gchar *type) return res; } -static void initialize_default_value_table() +static void initialize_default_value_table(void) { defaultValues = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); (void)g_hash_table_insert(defaultValues, g_strdup("gboolean"), g_strdup("FALSE")); diff --git a/src/libical-glib/tools/xml-parser.c b/src/libical-glib/tools/xml-parser.c index a9cf2704..d3fdd44c 100644 --- a/src/libical-glib/tools/xml-parser.c +++ b/src/libical-glib/tools/xml-parser.c @@ -15,7 +15,7 @@ #include "xml-parser.h" -Structure *structure_new() +Structure *structure_new(void) { Structure *structure; @@ -74,7 +74,7 @@ void structure_free(Structure * structure) g_free(structure); } -Declaration *declaration_new() +Declaration *declaration_new(void) { Declaration *declaration = g_new0(Declaration, 1); @@ -98,7 +98,7 @@ void declaration_free(Declaration * declaration) g_free(declaration); } -Method *method_new() +Method *method_new(void) { Method *method; @@ -141,7 +141,7 @@ void method_free(Method * method) g_free(method); } -Parameter *parameter_new() +Parameter *parameter_new(void) { Parameter *parameter; @@ -184,7 +184,7 @@ void parameter_free(Parameter * para) g_free(para); } -Ret *ret_new() +Ret *ret_new(void) { Ret *ret; @@ -222,7 +222,7 @@ void ret_free(Ret * ret) g_free(ret); } -Enumeration *enumeration_new() +Enumeration *enumeration_new(void) { Enumeration *enumeration = g_new0(Enumeration, 1); diff --git a/src/libical-glib/tools/xml-parser.h b/src/libical-glib/tools/xml-parser.h index bccbb4d3..bffb5a17 100644 --- a/src/libical-glib/tools/xml-parser.h +++ b/src/libical-glib/tools/xml-parser.h @@ -83,17 +83,17 @@ typedef struct Enumeration { gchar *comment; } Enumeration; -Structure *structure_new(); +Structure *structure_new(void); void structure_free(Structure *structure); -Method *method_new(); +Method *method_new(void); void method_free(Method *method); -Parameter *parameter_new(); +Parameter *parameter_new(void); void parameter_free(Parameter *para); -Ret *ret_new(); +Ret *ret_new(void); void ret_free(Ret *ret); -Enumeration *enumeration_new(); +Enumeration *enumeration_new(void); void enumeration_free(Enumeration *enumeration); -Declaration *declaration_new(); +Declaration *declaration_new(void); void declaration_free(Declaration *declaration); GList *get_list_from_string(const gchar *str); diff --git a/src/libical/caldate.c b/src/libical/caldate.c index e26926b4..f3d600c2 100644 --- a/src/libical/caldate.c +++ b/src/libical/caldate.c @@ -55,8 +55,7 @@ * */ -long caldat( date ) -struct ut_instant * date; +long caldat( struct ut_instant * date ) { double frac; long jd; @@ -129,8 +128,7 @@ struct ut_instant * date; * 50 Year canon of solar eclipses: 1986-2035 */ -double juldat( date ) -struct ut_instant * date; +double juldat( struct ut_instant * date ) { double frac, gyr; long iy0, im0; diff --git a/src/libical/icalduration.c b/src/libical/icalduration.c index d142c0d5..3f9516da 100644 --- a/src/libical/icalduration.c +++ b/src/libical/icalduration.c @@ -301,7 +301,7 @@ int icaldurationtype_is_null_duration(struct icaldurationtype d) following the philosophy of unix errno. we set the is_neg to -1 to indicate that this is a bad duration. */ -struct icaldurationtype icaldurationtype_bad_duration() +struct icaldurationtype icaldurationtype_bad_duration(void) { struct icaldurationtype d; diff --git a/src/libical/icalerror.c b/src/libical/icalerror.c index e10fd72e..e6081c2b 100644 --- a/src/libical/icalerror.c +++ b/src/libical/icalerror.c @@ -92,7 +92,7 @@ void icalerror_crash_here(void) assert(*p); } -void icalerror_clear_errno() +void icalerror_clear_errno(void) { icalerrno = ICAL_NO_ERROR; } @@ -108,7 +108,7 @@ void icalerror_set_errors_are_fatal(int fatal) icalerror_errors_are_fatal = (fatal != 0); } -int icalerror_get_errors_are_fatal() +int icalerror_get_errors_are_fatal(void) { return icalerror_errors_are_fatal; } diff --git a/src/libical/icalmemory.c b/src/libical/icalmemory.c index 6c1bd9ca..db4fe4ea 100644 --- a/src/libical/icalmemory.c +++ b/src/libical/icalmemory.c @@ -224,7 +224,7 @@ void *icalmemory_tmp_buffer(size_t size) return buf; } -void icalmemory_free_ring() +void icalmemory_free_ring(void) { buffer_ring *br; diff --git a/src/libical/pvl.c b/src/libical/pvl.c index 960941a7..726ff835 100644 --- a/src/libical/pvl.c +++ b/src/libical/pvl.c @@ -76,7 +76,7 @@ typedef struct pvl_list_t * @return Pointer to the new list, 0 if there is no available memory. */ -pvl_list pvl_newlist() +pvl_list pvl_newlist(void) { struct pvl_list_t *L; diff --git a/src/libicalss/icalsslexer.c b/src/libicalss/icalsslexer.c index f889016c..ac3a2ab7 100644 --- a/src/libicalss/icalsslexer.c +++ b/src/libicalss/icalsslexer.c @@ -1961,7 +1961,7 @@ void ssfree (void * ptr ) -int sswrap() +int sswrap(void) { return 1; } diff --git a/src/libicalvcal/vcc.c b/src/libicalvcal/vcc.c index 19eb9a16..97632198 100644 --- a/src/libicalvcal/vcc.c +++ b/src/libicalvcal/vcc.c @@ -444,7 +444,7 @@ static int pushVObject(const char *prop) /* This pops the recently built vCard off the stack and returns it. */ -static VObject* popVObject() +static VObject* popVObject(void) { VObject *oldObj; if (ObjStackTop < 0) { @@ -577,7 +577,7 @@ static int lexWithinMode(enum LexMode mode) { return 0; } -static char lexGetc_() +static char lexGetc_(void) { /* get next char from input, no buffering. */ if (lexBuf.curPos == lexBuf.inputLen) @@ -594,7 +594,7 @@ static char lexGetc_() } } -static int lexGeta() +static int lexGeta(void) { ++lexBuf.len; return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); @@ -606,7 +606,7 @@ static int lexGeta_(int i) return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); } -static void lexSkipLookahead() { +static void lexSkipLookahead(void) { if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* don't skip EOF. */ lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; @@ -614,7 +614,7 @@ static void lexSkipLookahead() { } } -static int lexLookahead() { +static int lexLookahead(void) { int c = (lexBuf.len)? lexBuf.buf[lexBuf.getPtr]: lexGeta(); @@ -640,7 +640,7 @@ static int lexLookahead() { return c; } -static int lexGetc() { +static int lexGetc(void) { int c = lexLookahead(); if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=((char) EOF)) { /* EOF will remain in lookahead buffer */ @@ -650,14 +650,14 @@ static int lexGetc() { return c; } -static void lexSkipLookaheadWord() { +static void lexSkipLookaheadWord(void) { if (lexBuf.strsLen <= lexBuf.len) { lexBuf.len -= lexBuf.strsLen; lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; } } -static void lexClearToken() +static void lexClearToken(void) { lexBuf.strsLen = 0; } @@ -675,11 +675,11 @@ static void lexAppendc(int c) } } -static char* lexStr() { +static char* lexStr(void) { return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); } -static void lexSkipWhite() { +static void lexSkipWhite(void) { int c = lexLookahead(); while (c == ' ' || c == '\t') { lexSkipLookahead(); @@ -687,7 +687,7 @@ static void lexSkipWhite() { } } -static char* lexGetWord() { +static char* lexGetWord(void) { int c; lexSkipWhite(); lexClearToken(); @@ -712,7 +712,7 @@ static void lexPushLookaheadc(int c) { lexBuf.len += 1; } -static char* lexLookaheadWord() { +static char* lexLookaheadWord(void) { /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 / and thing bigger than that will stop the lookahead and return 0; / leading white spaces are not recoverable. @@ -778,7 +778,7 @@ static void handleMoreRFC822LineBreak(int c) { } } -static char* lexGet1Value() { +static char* lexGet1Value(void) { int c; lexSkipWhite(); c = lexLookahead(); @@ -849,7 +849,7 @@ void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) } -static void finiLex() { +static void finiLex(void) { VObject* vobj, *topobj = 0; while(vobj = popVObject(), vobj) { topobj = vobj; @@ -863,7 +863,7 @@ static void finiLex() { /* This parses and converts the base64 format for binary encoding into * a decoded buffer (allocated with new). See RFC 1521. */ -static char * lexGetDataFromBase64() +static char * lexGetDataFromBase64(void) { size_t bytesLen = 0, bytesMax = 0; int quadIx = 0, pad = 0; @@ -985,7 +985,7 @@ static int match_begin_end_name(int end) { return 0; } -static char* lexGetQuotedPrintable() +static char* lexGetQuotedPrintable(void) { char cur; @@ -1042,7 +1042,7 @@ EndString: return lexStr(); } /* LexQuotedPrintable */ -int yylex() { +int yylex(void) { int lexmode = LEXMODE(); if (lexmode == L_VALUES) { @@ -1160,7 +1160,7 @@ int yylex() { /*** Public Functions ****/ /***************************************************************************/ -static VObject* Parse_MIMEHelper() +static VObject* Parse_MIMEHelper(void) { ObjStackTop = -1; mime_numErrors = 0; diff --git a/src/libicalvcal/vobject.c b/src/libicalvcal/vobject.c index 10d0cf5a..03a4249c 100644 --- a/src/libicalvcal/vobject.c +++ b/src/libicalvcal/vobject.c @@ -682,7 +682,7 @@ void unUseStr(const char *s) } } -void cleanStrTbl() +void cleanStrTbl(void) { int i; for (i=0; i */ -void test_recur_parameter_bug() +void test_recur_parameter_bug(void) { static const char test_icalcomp_str[] = "BEGIN:VEVENT\r\n" @@ -1367,7 +1367,7 @@ void test_recur_parameter_bug() icalcomponent_free(icalcomp); } -void test_duration() +void test_duration(void) { struct icaldurationtype d; @@ -1450,7 +1450,7 @@ void test_duration() str_is("P51DT5H", icaldurationtype_as_ical_string(d), "P51DT5H"); } -void test_period() +void test_period(void) { struct icalperiodtype p; icalvalue *v; @@ -1472,7 +1472,7 @@ void test_period() icalvalue_free(v); } -void test_strings() +void test_strings(void) { icalvalue *v; @@ -1495,7 +1495,7 @@ void test_strings() } /* Check RFC6868 encoding of "unsafe" chars in parameter values, such as '\n' */ -void test_tzid_escape() +void test_tzid_escape(void) { icalparameter *tzid; icalproperty *prop; @@ -1514,7 +1514,7 @@ void test_tzid_escape() icalproperty_free(prop); } -void test_requeststat() +void test_requeststat(void) { icalcomponent *c; icalproperty *p; @@ -1626,7 +1626,7 @@ void test_requeststat() icalcomponent_free(c); } -void test_dtstart() +void test_dtstart(void) { struct icaltimetype tt, tt2; @@ -2011,7 +2011,7 @@ void do_test_time(const char *zone) 0); } -void test_iterators() +void test_iterators(void) { icalcomponent *c, *inner, *next; icalcompiter i; @@ -2129,7 +2129,7 @@ void test_iterators() icalcomponent_free(c); } -void test_time() +void test_time(void) { const char *zones[6] = { @@ -2149,7 +2149,7 @@ void test_time() } } -void test_icalset() +void test_icalset(void) { icalcomponent *c; @@ -2174,7 +2174,7 @@ void test_icalset() icalset_free(d); } -void test_overlaps() +void test_overlaps(void) { icalcomponent *cset, *c; icalset *set; @@ -2251,7 +2251,7 @@ void test_overlaps() icalcomponent_free(c); } -void test_fblist() +void test_fblist(void) { icalspanlist *sl, *new_sl; icalfileset_options options = { O_RDONLY, 0644, 0, NULL }; @@ -2387,7 +2387,7 @@ void test_fblist() icalset_free(set); } -void test_convenience() +void test_convenience(void) { icalcomponent *c; int duration; @@ -2553,7 +2553,7 @@ void test_convenience() icalcomponent_free(c); } -void test_time_parser() +void test_time_parser(void) { struct icaltimetype tt; @@ -2586,7 +2586,7 @@ void test_time_parser() icalerror_set_errors_are_fatal(1); } -void test_recur_parser() +void test_recur_parser(void) { struct icalrecurrencetype rt; icalvalue *v = NULL; @@ -2629,7 +2629,7 @@ char *ical_strstr(const char *haystack, const char *needle) return strstr(haystack, needle); } -void test_start_of_week() +void test_start_of_week(void) { struct icaltimetype tt2; struct icaltimetype tt1 = icaltime_from_string("19900110"); @@ -2663,7 +2663,7 @@ void test_start_of_week() } while (tt1.year < 2010); } -void test_doy() +void test_doy(void) { struct icaltimetype tt1, tt2; short doy, doy2; @@ -2760,7 +2760,7 @@ void test_doy() ok("day of year == 60", (doy == 60)); } -void test_x() +void test_x(void) { static const char test_icalcomp_str[] = "BEGIN:VEVENT\r\n" @@ -2807,7 +2807,7 @@ void test_x() icalcomponent_free(icalcomp); } -void test_gauge_sql() +void test_gauge_sql(void) { icalgauge *g; const char *str; @@ -2860,7 +2860,7 @@ void test_gauge_sql() icalgauge_free(g); } -void test_gauge_compare() +void test_gauge_compare(void) { icalgauge *g; icalcomponent *c; @@ -3160,7 +3160,7 @@ icalcomponent *make_component(int i) return c; } -void test_fileset() +void test_fileset(void) { #if defined(HAVE_UNLINK) icalset *fs; @@ -3243,7 +3243,7 @@ void microsleep(int us) #endif /*Windows Sleep is useless for microsleeping */ } -void test_file_locks() +void test_file_locks(void) { #if defined(HAVE_WAITPID) && defined(HAVE_FORK) && defined(HAVE_UNLINK) pid_t pid; @@ -3376,7 +3376,7 @@ void test_file_locks() #endif } -void test_action() +void test_action(void) { icalcomponent *c; icalproperty *p; @@ -3416,7 +3416,7 @@ void test_action() icalcomponent_free(c); } -void test_trigger() +void test_trigger(void) { struct icaltriggertype tr; icalcomponent *c; @@ -3539,7 +3539,7 @@ void test_trigger() icalproperty_free(p); } -void test_rdate() +void test_rdate(void) { struct icaldatetimeperiodtype dtp; icalproperty *p; @@ -3632,7 +3632,7 @@ void test_rdate() icalproperty_free(p); } -void test_langbind() +void test_langbind(void) { icalcomponent *c, *inner; icalproperty *p; @@ -3707,7 +3707,7 @@ void test_langbind() icalcomponent_free(c); } -void test_property_parse() +void test_property_parse(void) { icalcomponent *c; icalproperty *p; @@ -3746,7 +3746,7 @@ void test_property_parse() icalcomponent_free(c); } -void test_value_parameter() +void test_value_parameter(void) { icalcomponent *c; icalproperty *p; @@ -3778,7 +3778,7 @@ void test_value_parameter() icalcomponent_free(c); } -void test_empty_parameter() +void test_empty_parameter(void) { icalcomponent *c; icalproperty *p; @@ -3806,7 +3806,7 @@ void test_empty_parameter() icalcomponent_free(c); } -void test_x_parameter() +void test_x_parameter(void) { icalcomponent *c; icalproperty *p; @@ -3842,7 +3842,7 @@ void test_x_parameter() icalcomponent_free(c); } -void test_x_property() +void test_x_property(void) { icalcomponent *c; icalproperty *p; @@ -3867,7 +3867,7 @@ void test_x_property() icalcomponent_free(c); } -void test_utcoffset() +void test_utcoffset(void) { icalcomponent *c; @@ -3884,7 +3884,7 @@ void test_utcoffset() icalcomponent_free(c); } -void test_attach() +void test_attach(void) { icalcomponent *c; @@ -3904,7 +3904,7 @@ void test_attach() icalcomponent_free(c); } -void test_attach_caldav() +void test_attach_caldav(void) { icalcomponent *c; icalproperty *p; @@ -3961,7 +3961,7 @@ void test_attach_caldav() icalcomponent_free(c); } -void test_attach_url() +void test_attach_url(void) { static const char test_icalcomp_str_attachwithurl[] = "BEGIN:VALARM\r\n" "ATTACH:foofile\r\n" "END:VALARM\r\n"; @@ -3990,7 +3990,7 @@ static void test_free_attach_data(char *data, void *user_data) (*pbeen_called)++; } -void test_attach_data() +void test_attach_data(void) { static const char test_icalcomp_str_attachwithdata[] = "BEGIN:VALARM\r\n" "ATTACH;VALUE=BINARY:foofile\r\n" "END:VALARM\r\n"; diff --git a/src/test/regression.h b/src/test/regression.h index 9c5aab88..88a29509 100644 --- a/src/test/regression.h +++ b/src/test/regression.h @@ -66,7 +66,7 @@ extern "C" void test_header(const char *title, int test_set); void test_start(int); int test_end(void); - void test_run(const char *test_name, void (*test_fcn) (), int do_test, int headeronly); + void test_run(const char *test_name, void (*test_fcn) (void), int do_test, int headeronly); #ifdef __cplusplus } diff --git a/src/test/timezones.c b/src/test/timezones.c index 935e912d..6beff2f9 100644 --- a/src/test/timezones.c +++ b/src/test/timezones.c @@ -26,7 +26,7 @@ #define MAX_FAILURE_RATE 1 -int main() +int main(void) { icalarray *timezones; icaltimezone *zone, *utc_zone; -- cgit v1.2.1