Fix crash issues when inserting a vcard which has custom type data 25/229725/1 submit/tizen/20200409.163033
authorjk.koo <jk.koo@samsung.com>
Fri, 3 Apr 2020 05:30:59 +0000 (14:30 +0900)
committerjk.koo <jk.koo@samsung.com>
Fri, 3 Apr 2020 05:30:59 +0000 (14:30 +0900)
Change-Id: I8441750f96b365b2f2e148913560092e4b5b5b82
Signed-off-by: jk.koo <jk.koo@samsung.com>
common/ctsvc_vcard.c

index 70e20ec..9b2b9bc 100644 (file)
@@ -2390,6 +2390,33 @@ static int __ctsvc_vcard_check_content_type(char **vcard)
        }
 }
 
+static bool __ctsvc_vcard_has_unsupported_format(const char *row)
+{
+       RETV_IF(NULL == row, false);
+
+       char *xcustom1 = strstr(row, "XCUSTOM");
+       char *xcustom2 = strstr(row, "X-CUSTOM");
+       char *quoted1 = strstr(row, "QUOTEDPRINTABLE");
+       char *quoted2 = strstr(row, "QUOTED-PRINTABLE");
+       char *end_of_raw = strchr(row, '\n');
+       bool has_xcustom = false;
+       bool has_quoted = false;
+
+       if ((xcustom1 != NULL && xcustom1 < end_of_raw) ||(xcustom2 != NULL && xcustom2 < end_of_raw))
+               has_xcustom = true;
+
+       if ((quoted1 != NULL && quoted1 < end_of_raw) ||(quoted2 != NULL && quoted2 < end_of_raw))
+               has_quoted = true;
+
+       /* quoted-printable is not supported in custom type */
+       if (has_xcustom && has_quoted) {
+               INFO("This row has unsupported format");
+               return true;
+       }
+
+       return false;
+}
+
 static inline char* __ctsvc_vcard_pass_unsupported(char *vcard)
 {
        while (*vcard) {
@@ -2593,7 +2620,7 @@ static inline char* __ctsvc_vcard_translate_charset(char *src, int len)
        return NULL;
 }
 
-static void __ctsvc_vcard_get_prefix(char **prefix, char *src)
+static void __ctsvc_vcard_get_prefix(char **prefix, const char *src)
 {
        char *temp = strchr(src, ':');
        if (temp) {
@@ -3948,7 +3975,7 @@ static inline int __ctsvc_vcard_get_contact(int ver, char *vcard, contacts_recor
 
                bool base64_encoded = false;
                type = __ctsvc_vcard_check_content_type(&cursor);
-               if (CTSVC_VCARD_VALUE_NONE == type) {
+               if (CTSVC_VCARD_VALUE_NONE == type || __ctsvc_vcard_has_unsupported_format(cursor)) {
                        new_start = __ctsvc_vcard_pass_unsupported(cursor);
                        if (new_start) {
                                cursor = new_start;