From 993c60b8ac2faba6a04ef06ea57c4f488de95b6e Mon Sep 17 00:00:00 2001 From: Haejeong Kim Date: Thu, 27 Apr 2017 14:52:12 +0900 Subject: [PATCH] Svace issue fix. use snprintf instead of memcpy Change-Id: I5ba1a8d1fa53284469bfc124f7733dc42fe1b8aa --- src/common/media-svc-util.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index b2e6afb..c96f917 100755 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -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) -- 2.7.4