summaryrefslogtreecommitdiff
path: root/src/libical/icalcomponent.c
diff options
context:
space:
mode:
authorKen Murchison <murch@fastmail.com>2019-10-16 16:29:42 -0400
committerAllen Winter <allen.winter@kdab.com>2019-10-19 11:00:50 -0400
commit59362ff6121795c731cc2cb7f29655cf66d58a58 (patch)
treea809feee441241c861905fb37b2ad00ad5559674 /src/libical/icalcomponent.c
parent805be190c64665702583bd3e9b86f06bd2005110 (diff)
downloadlibical-git-59362ff6121795c731cc2cb7f29655cf66d58a58.tar.gz
icalcomponent.c, icalproperty.c: Rewrite of normalization code to (hopefully) fix crashes and leaks
Diffstat (limited to 'src/libical/icalcomponent.c')
-rw-r--r--src/libical/icalcomponent.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/libical/icalcomponent.c b/src/libical/icalcomponent.c
index 70c1e342..c16bb6dc 100644
--- a/src/libical/icalcomponent.c
+++ b/src/libical/icalcomponent.c
@@ -2650,55 +2650,52 @@ void icalcomponent_normalize(icalcomponent *comp)
pvl_list sorted_props = pvl_newlist();
pvl_list sorted_comps = pvl_newlist();
icalproperty *prop;
- icalcomponent *mycomp;
+ icalcomponent *sub;
+ /* Normalize properties into sorted list */
while ((prop = pvl_pop(comp->properties)) != 0) {
- int nparams = icalproperty_count_parameters(prop);
+ int nparams, remove = 0;
- icalproperty_set_parent(prop, 0);
+ icalproperty_normalize(prop);
+
+ nparams = icalproperty_count_parameters(prop);
- /* Skip unparameterized properties having default values */
+ /* Remove unparameterized properties having default values */
if (nparams == 0) {
switch (icalproperty_isa(prop)) {
case ICAL_CALSCALE_PROPERTY:
if (strcmp("GREGORIAN", icalproperty_get_calscale(prop)) == 0) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
case ICAL_CLASS_PROPERTY:
if (icalproperty_get_class(prop) == ICAL_CLASS_PUBLIC) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
case ICAL_PRIORITY_PROPERTY:
if (icalproperty_get_priority(prop) == 0) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
case ICAL_TRANSP_PROPERTY:
if (icalproperty_get_transp(prop) == ICAL_TRANSP_OPAQUE) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
case ICAL_REPEAT_PROPERTY:
if (icalproperty_get_repeat(prop) == 0) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
case ICAL_SEQUENCE_PROPERTY:
if (icalproperty_get_sequence(prop) == 0) {
- icalproperty_free(prop);
- continue;
+ remove = 1;
}
break;
@@ -2707,16 +2704,22 @@ void icalcomponent_normalize(icalcomponent *comp)
}
}
- icalproperty_normalize(prop);
- pvl_insert_ordered(sorted_props, prop_compare, prop);
+ if (remove) {
+ icalproperty_set_parent(prop, 0); // MUST NOT have a parent to free
+ icalproperty_free(prop);
+ }
+ else {
+ pvl_insert_ordered(sorted_props, prop_compare, prop);
+ }
}
pvl_free(comp->properties);
comp->properties = sorted_props;
- while ((mycomp = pvl_pop(comp->components)) != 0) {
- icalcomponent_normalize(mycomp);
- pvl_insert_ordered(sorted_comps, comp_compare, mycomp);
+ /* Normalize sub-components into sorted list */
+ while ((sub = pvl_pop(comp->components)) != 0) {
+ icalcomponent_normalize(sub);
+ pvl_insert_ordered(sorted_comps, comp_compare, sub);
}
pvl_free(comp->components);