forked from libical/libical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add icalparser_ctrl to handle CONTROL characters during parse
RFC 5545 section 3.1 defines CONTROL characters to be byte values in the decimal ranges [0-8], [10-31] as well as 127. Of these, all but 10 (LF) and 13 (CR) are not allowed to be part of any valid content-line produced by the "contentline" ABNF defined in this section. However, the current libical parser allows such illegal values to occur at almost all places within iCalendar and preserves them in TEXT values as well as non-standard property names. This causes libical to silently accept invalid iCalendar input and generate invalid output for such data. This patch adds the icalparser_ctrl setting to define how to handle invalid CONTROL characters during parse: * KEEP: preserve current libical behaviour * OMIT: silently ignores such characters during parse * ERROR: rejects the content-line and inserts an error For backwards-compability, the default setting is KEEP.
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifdef HAVE_CONFIG_H | ||
#include <config.h> | ||
#endif | ||
|
||
#include "libical/ical.h" | ||
|
||
static void assert_ctrl(enum icalparser_ctrl ctrl, | ||
const char *data, | ||
const char *want_desc, | ||
int want_xlicerror) | ||
{ | ||
icalparser_set_ctrl(ctrl); | ||
|
||
icalcomponent *ical = icalparser_parse_string(data); | ||
assert(ical); | ||
|
||
icalcomponent *comp = icalcomponent_get_first_real_component(ical); | ||
assert(comp); | ||
|
||
if (want_desc) { | ||
assert(!strcmp(want_desc, icalcomponent_get_description(comp))); | ||
} else { | ||
assert(!icalcomponent_get_first_property(comp, ICAL_DESCRIPTION_PROPERTY)); | ||
} | ||
|
||
if (want_xlicerror) { | ||
assert(icalcomponent_get_first_property(comp, ICAL_XLICERROR_PROPERTY)); | ||
} else { | ||
assert(!icalcomponent_get_first_property(comp, ICAL_XLICERROR_PROPERTY)); | ||
} | ||
|
||
icalcomponent_free(ical); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc != 1) { | ||
fprintf(stderr, "Usage: %s\n", argv[0]); | ||
return 0; | ||
} | ||
|
||
// Assert default value | ||
assert(icalparser_get_ctrl() == ICALPARSER_CTRL_KEEP); | ||
|
||
// Assert icalparser_ctrl settings | ||
static const char *data = "" | ||
"BEGIN:VCALENDAR\r\n" | ||
"VERSION:2.0\r\n" | ||
"PRODID:-//ACME/DesktopCalendar//E\r\n" | ||
"CALSCALE:GREGORIAN\r\n" | ||
"BEGIN:VEVENT\r\n" | ||
"DTSTART:20160929T010000Z\r\n" | ||
"DURATION:PT1H\r\n" | ||
"UID:40d6fe3c-6a51-489e-823e-3ea22f427a3e\r\n" | ||
"CREATED:20150928T125212Z\r\n" | ||
"LAST-MODIFIED:20150928T132434Z\r\n" | ||
"SUMMARY:test\r\n" | ||
"DESCRIPTION:ct\x15rl\r\n" // this contains a CTRL char | ||
"END:VEVENT\r\n" | ||
"END:VCALENDAR\r\n"; | ||
|
||
assert_ctrl(ICALPARSER_CTRL_KEEP, data, "ct\x15rl", 0); | ||
assert_ctrl(ICALPARSER_CTRL_OMIT, data, "ctrl", 0); | ||
assert_ctrl(ICALPARSER_CTRL_ERROR, data, NULL, 1); | ||
|
||
return 0; | ||
} |