Fix bug 577220 - Problem when parsing Outlook "X-ALT-DESC" property. r=philipp
authorSimon Vaillancourt <nomisvai@gmail.com>
Thu, 09 Dec 2010 07:22:00 +0100
changeset 6945 180063a9fe4df473c2ce0fd2424acdceee81cb45
parent 6944 9093f7af161599259a22351b827b36f0ea59676c
child 6946 a2582159d2954a54de9aaf4aff1bbfabe2a92de0
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs577220
Fix bug 577220 - Problem when parsing Outlook "X-ALT-DESC" property. r=philipp
calendar/libical/src/libical/icalvalue.c
--- a/calendar/libical/src/libical/icalvalue.c
+++ b/calendar/libical/src/libical/icalvalue.c
@@ -257,16 +257,82 @@ static char* icalmemory_strdup_and_dequo
 	
     }
 
     *pout = '\0';
 
     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
  *
  * This is a bad API, as it forces callers to specify their own X type.
  * This function should take care of this by itself.
  */
 static
 icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str)
@@ -829,76 +895,18 @@ static char* icalvalue_recur_as_ical_str
 
  /* @todo This is not RFC2445 compliant.
  * The RFC only allows:
  * TSAFE-CHAR = %x20-21 / %x23-2B / %x2D-39 / %x3C-5B / %x5D-7E / NON-US-ASCII
  * As such, \t\r\b\f are not allowed, not even escaped
  */
 
 static char* icalvalue_text_as_ical_string_r(const icalvalue* value) {
-    char *str;
-    char *str_p;
-    const char *p;
-    size_t buf_sz;
-
-    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;
-	    }
+    return icalmemory_strdup_and_quote(value->data.v_string);
 
-	    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;
 }
 
 
 static char* icalvalue_text_as_ical_string(const icalvalue* value) {
 	char *buf;
 	buf = icalvalue_text_as_ical_string_r(value);
 	icalmemory_add_tmp_buffer(buf);
 	return buf;
@@ -1170,17 +1178,17 @@ icalvalue_as_ical_string_r(const icalval
         if(value->x_value !=0){
             return icalmemory_strdup(value->x_value);
         }
 
         return icalproperty_enum_to_string_r(value->data.v_enum);
         
     case ICAL_X_VALUE: 
 	if (value->x_value != 0)
-            return icalmemory_strdup(value->x_value);
+            return icalmemory_strdup_and_quote(value->x_value);
 
     /* FALLTHRU */
 
     case ICAL_NO_VALUE:
     default:
 	{
 	    return 0;
 	}