From 961df340e710b016948fb3f4b23c3fcb53240513 Mon Sep 17 00:00:00 2001 From: Simon Vaillancourt Date: Thu, 9 Dec 2010 07:22:00 +0100 Subject: [PATCH] Fix bug 577220 - Problem when parsing Outlook "X-ALT-DESC" property. r=philipp --HG-- extra : rebase_source : 11c3ff7870f3f0d26740b6f87a77636c4ef673e1 --- calendar/libical/src/libical/icalvalue.c | 128 ++++++++++++----------- 1 file changed, 68 insertions(+), 60 deletions(-) diff --git a/calendar/libical/src/libical/icalvalue.c b/calendar/libical/src/libical/icalvalue.c index 53147a713e..01e1bbec3d 100644 --- a/calendar/libical/src/libical/icalvalue.c +++ b/calendar/libical/src/libical/icalvalue.c @@ -262,6 +262,72 @@ static char* icalmemory_strdup_and_dequote(const char* str) return out; } + /* + * Returns a quoted copy of a string + */ + +static char* icalmemory_strdup_and_quote(const char* unquoted_str) +{ + char *str; + char *str_p; + const char *p; + size_t buf_sz; + + buf_sz = strlen(unquoted_str)+1; + + str_p = str = (char*)icalmemory_new_buffer(buf_sz); + + if (str_p == 0){ + return 0; + } + + for(p=unquoted_str; *p!=0; p++){ + + switch(*p){ + case '\n': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); + break; + } + + case '\t': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); + break; + } + case '\r': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); + break; + } + case '\b': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); + break; + } + case '\f': { + icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); + break; + } + + case ';': + case ',': + case '"': + case '\\':{ + icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); + icalmemory_append_char(&str,&str_p,&buf_sz,*p); + break; + } + + default: { + icalmemory_append_char(&str,&str_p,&buf_sz,*p); + } + } + } + /* Assume the last character is not a '\0' and add one. We could + check *str_p != 0, but that would be an uninitialized memory + read. */ + + + icalmemory_append_char(&str,&str_p,&buf_sz,'\0'); + return str; +} /* * FIXME * @@ -834,66 +900,8 @@ static char* icalvalue_recur_as_ical_string_r(const icalvalue* value) */ static char* icalvalue_text_as_ical_string_r(const icalvalue* value) { - char *str; - char *str_p; - const char *p; - size_t buf_sz; + return icalmemory_strdup_and_quote(value->data.v_string); - buf_sz = strlen(value->data.v_string)+1; - - str_p = str = (char*)icalmemory_new_buffer(buf_sz); - - if (str_p == 0){ - return 0; - } - - for(p=value->data.v_string; *p!=0; p++){ - - switch(*p){ - case '\n': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); - break; - } - - case '\t': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); - break; - } - case '\r': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); - break; - } - case '\b': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); - break; - } - case '\f': { - icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); - break; - } - - case ';': - case ',': - case '"': - case '\\':{ - icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); - icalmemory_append_char(&str,&str_p,&buf_sz,*p); - break; - } - - default: { - icalmemory_append_char(&str,&str_p,&buf_sz,*p); - } - } - } - - /* Assume the last character is not a '\0' and add one. We could - check *str_p != 0, but that would be an uninitialized memory - read. */ - - - icalmemory_append_char(&str,&str_p,&buf_sz,'\0'); - return str; } @@ -1175,7 +1183,7 @@ icalvalue_as_ical_string_r(const icalvalue* value) case ICAL_X_VALUE: if (value->x_value != 0) - return icalmemory_strdup(value->x_value); + return icalmemory_strdup_and_quote(value->x_value); /* FALLTHRU */