From 1209222f6dac9c3e2ba67975e4caacd76ddca983 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Mon, 7 Aug 2023 12:08:18 +0200 Subject: [PATCH] Revert "freebusy: trim shared_ptr from internal API" This reverts commit bcf55c2c46b0095b1df6ee1221b06d86dfc1d272. ptz_component can be an empty std::optional; as a result, ptz_component->component_list is invalid. ==22636==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 ==22636==The signal is caused by a READ memory access. ==22636==Hint: address points to the zero page. f1 std::__cxx11::basic_string, std::allocator >::c_str() const /usr/include/c++/7/bits/basic_string.h:2281 f2 ical_utc_to_datetime(ical_component const*, long, ICAL_TIME*) lib/email/ical.cpp:1503 f3 recurrencepattern_to_rrule tools/freebusy.cpp:266 f4 find_recurrence_times tools/freebusy.cpp:292 f5 get_freebusy tools/freebusy.cpp:759 f6 main tools/freebusy.cpp:1023 Fixes: gromox-1.28-218-gbcf55c2c4 --- tools/freebusy.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/freebusy.cpp b/tools/freebusy.cpp index 1a5106877..00de4273d 100644 --- a/tools/freebusy.cpp +++ b/tools/freebusy.cpp @@ -185,7 +185,7 @@ static std::optional tzstruct_to_vtimezone(int year, return {}; } -static BOOL recurrencepattern_to_rrule(const ical_component &tzcom, +static BOOL recurrencepattern_to_rrule(const ical_component *tzcom, time_t whole_start_time, const APPOINTMENT_RECUR_PAT *apr, ICAL_RRULE *pirrule) try { @@ -263,7 +263,7 @@ static BOOL recurrencepattern_to_rrule(const ical_component &tzcom, piline->append_value("COUNT", std::to_string(apr->recur_pat.occurrencecount)); } else if (apr->recur_pat.endtype == ENDTYPE_AFTER_DATE) { char tmp_buff[1024]; - ical_utc_to_datetime(&tzcom, rop_util_rtime_to_unix(apr->recur_pat.enddate + apr->starttimeoffset), &itime); + ical_utc_to_datetime(tzcom, rop_util_rtime_to_unix(apr->recur_pat.enddate + apr->starttimeoffset), &itime); sprintf_dtutc(tmp_buff, std::size(tmp_buff), itime); piline->append_value("UNTIL", tmp_buff); } @@ -273,14 +273,14 @@ static BOOL recurrencepattern_to_rrule(const ical_component &tzcom, return FALSE; piline->append_value("WKST", wd); } - return ical_parse_rrule(&tzcom, whole_start_time, + return ical_parse_rrule(tzcom, whole_start_time, &piline->value_list, pirrule) ? TRUE : false; } catch (const std::bad_alloc &) { fprintf(stderr, "E-2093: ENOMEM\n"); return false; } -static BOOL find_recurrence_times(ical_component &tzcom, +static BOOL find_recurrence_times(const ical_component *tzcom, time_t whole_start_time, const APPOINTMENT_RECUR_PAT *apr, time_t start_time, time_t end_time, std::list &plist) { @@ -295,7 +295,7 @@ static BOOL find_recurrence_times(ical_component &tzcom, plist.clear(); do { auto itime = irrule.instance_itime; - ical_itime_to_utc(&tzcom, itime, &tmp_time); + ical_itime_to_utc(tzcom, itime, &tmp_time); if (tmp_time < start_time) continue; ical_itime_to_utc(NULL, itime, &tmp_time1); @@ -318,7 +318,7 @@ static BOOL find_recurrence_times(ical_component &tzcom, tmp_time = rop_util_rtime_to_unix(apr->pexceptioninfo[i].startdatetime); ICAL_TIME itime; ical_utc_to_datetime(NULL, tmp_time, &itime); - ical_itime_to_utc(&tzcom, itime, &tmp_time); + ical_itime_to_utc(tzcom, itime, &tmp_time); if (tmp_time < start_time || tmp_time > end_time) continue; plist.emplace_back(); @@ -326,7 +326,7 @@ static BOOL find_recurrence_times(ical_component &tzcom, pevnode->start_time = tmp_time; tmp_time = rop_util_rtime_to_unix(apr->pexceptioninfo[i].enddatetime); ical_utc_to_datetime(NULL, tmp_time, &itime); - ical_itime_to_utc(&tzcom, itime, &tmp_time); + ical_itime_to_utc(tzcom, itime, &tmp_time); pevnode->end_time = tmp_time; pevnode->pexception = apr->pexceptioninfo + i; pevnode->pex_exception = apr->pextendedexception + i; @@ -756,7 +756,8 @@ static BOOL get_freebusy(const char *dir) if (ext_pull.g_apptrecpat(&apprecurr) != EXT_ERR_SUCCESS) continue; std::list event_list; - if (!find_recurrence_times(*ptz_component, whole_start_time, + if (!find_recurrence_times(ptz_component.has_value() ? + &ptz_component.value() : nullptr, whole_start_time, &apprecurr, g_start_time, g_end_time, event_list)) continue; while (event_list.size() > 0) {