Svace issue fix. use snprintf instead of memcpy 69/127369/1 accepted/tizen/unified/20170427.180232 submit/tizen/20170427.061312
authorHaejeong Kim <backto.kim@samsung.com>
Thu, 27 Apr 2017 05:52:12 +0000 (14:52 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Thu, 27 Apr 2017 05:52:12 +0000 (14:52 +0900)
Change-Id: I5ba1a8d1fa53284469bfc124f7733dc42fe1b8aa

src/common/media-svc-util.c

index b2e6afb..c96f917 100755 (executable)
@@ -2320,35 +2320,20 @@ int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type
 
 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
 {
-       char *result, *sr;
-       size_t i, count = 0;
-       size_t oldlen = strlen(olds);
-       if (oldlen < 1) return s;
-       size_t newlen = strlen(news);
-
-       if (newlen != oldlen) {
-               for (i = 0; s[i] != '\0';) {
-                       if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
-                       else i++;
-               }
-       } else i = strlen(s);
-
-
-       result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
-       if (result == NULL) return NULL;
+       char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+       memset(result, 0x00, sizeof(result));
 
-       sr = result;
-       while (*s) {
-               if (memcmp(s, olds, oldlen) == 0) {
-                       memcpy(sr, news, newlen);
-                       sr += newlen;
-                       s += oldlen;
-               } else *sr++ = *s++;
+       if (STRING_VALID(s) && STRING_VALID(olds) && STRING_VALID(news)) {
+               if (strncmp(s, olds, strlen(olds)) == 0) {
+                       snprintf(result, sizeof(result), "%s%s", news, s + strlen(olds));
+               }
        }
 
-       *sr = '\0';
+       if (STRING_VALID(result))
+               return g_strdup(result);
+       else
+               return NULL;
 
-       return result;
 }
 
 bool _media_svc_is_drm_file(const char *path)