sound: Fix string length in strncmp() 15/316015/2 accepted/tizen_9.0_unified tizen_9.0 accepted/tizen/9.0/unified/20241210.162006
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 9 Dec 2024 08:22:07 +0000 (17:22 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 9 Dec 2024 10:55:53 +0000 (19:55 +0900)
To compare include null character, the length should be
strlen() + 1 of literal string.
however strlen() + 1 logic was omitted.

Change-Id: I55fb51eb7e627ca7d21b44d9a2b9f3202c8c31fb
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/sound-parser.c

index 4e8c39b376d2c4c322719c8dae924e7b7885de23..e792bef7a3ad3b2a11058f6773764bc824899cc5 100644 (file)
@@ -76,17 +76,17 @@ static int parse_sound_theme_property(gpointer data, gpointer user_data)
        if (!prop || !sound_theme_elem)
                return 0;
 
-       if (!strncmp(prop->key, "SoundThemeId", strlen("SoundThemeId"))) {
+       if (!strncmp(prop->key, "SoundThemeId", strlen("SoundThemeId") + 1)) {
                sscanf(prop->value, "%d", (&sound_theme_elem->id));
                if (sound_theme_elem->id < 0)
                        return -EPERM;
-       } else if (!strncmp(prop->key, "SoundThemePath", strlen("SoundThemePath"))) {
+       } else if (!strncmp(prop->key, "SoundThemePath", strlen("SoundThemePath") + 1)) {
                int str_len = sizeof(prop->value);
                sound_theme_elem->conf_file_path = strndup(prop->value, str_len);
-       } else if (!strncmp(prop->key, "SoundThemeDefault", strlen("SoundThemeDefault"))) {
-               if (!strncmp(prop->value, "yes", strlen("yes")))
+       } else if (!strncmp(prop->key, "SoundThemeDefault", strlen("SoundThemeDefault") + 1)) {
+               if (!strncmp(prop->value, "yes", strlen("yes") + 1))
                        sound_theme_elem->is_default = 1;
-               else if (!strncmp(prop->value, "no", strlen("no")))
+               else if (!strncmp(prop->value, "no", strlen("no") + 1))
                        sound_theme_elem->is_default = 0;
                else
                        return -EPERM;
@@ -109,7 +109,7 @@ static int parse_sound_theme_section(const struct parse_result *result, void *da
        if (!result || !result->props)
                return 0;
 
-       if (strncmp("SoundTheme", result->section, strlen("SoundTheme")))
+       if (strncmp("SoundTheme", result->section, strlen("SoundTheme") + 1))
                return 0;
 
        SYS_G_LIST_FOREACH(result->props, temp_glist, extracted_section_prop) {
@@ -151,7 +151,7 @@ static int parse_sound_section(const struct parse_result *result, void *data)
        if (!result || !result->props)
                return 0;
 
-       if (!strncmp(result->section, "Sound", strlen("Sound"))) {
+       if (!strncmp(result->section, "Sound", strlen("Sound") + 1)) {
                if (is_default_theme_id_set()) {
                        _E("Failed to parse sound conf file, please check conf file description and follow the rules");
                        return -EINVAL;
@@ -217,7 +217,7 @@ static int parse_sound_property(const struct parse_result *result, void *data)
        if (!data)
                return -EINVAL;
 
-       if (strncmp(result->section, "Sound", strlen("Sound")))
+       if (strncmp(result->section, "Sound", strlen("Sound") + 1))
                return 0;
 
        sound_config_info = (GHashTable*)data;
@@ -269,7 +269,7 @@ static int parse_sound_pattern_priority_property(const struct parse_result *resu
        if (!data)
                return -EINVAL;
 
-       if (strncmp("SoundPatternPriority", result->section, strlen("SoundPatternPriority")))
+       if (strncmp("SoundPatternPriority", result->section, strlen("SoundPatternPriority") + 1))
                return 0;
 
        sound_config_info = (GHashTable*)data;