sound: Replace insecure string comparison macro to strncmp 30/320630/3 accepted/tizen/9.0/unified/20241125.071518
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 18 Nov 2024 04:13:57 +0000 (13:13 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 21 Nov 2024 10:44:12 +0000 (19:44 +0900)
The MATCH macro from the libsyscommon was omitted secure string length comparison.
When comparing strings with the strncmp function,
it is safer to use a parameter length of strlen + 1.
For clear comparison, strings are compared by the length of the literal string.

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

index 4c43a98f1ce6dc115dcf1f0f2d0bf89543d9f768..4e8c39b376d2c4c322719c8dae924e7b7885de23 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 (MATCH(prop->key, "SoundThemeId")) {
+       if (!strncmp(prop->key, "SoundThemeId", strlen("SoundThemeId"))) {
                sscanf(prop->value, "%d", (&sound_theme_elem->id));
                if (sound_theme_elem->id < 0)
                        return -EPERM;
-       } else if (MATCH(prop->key, "SoundThemePath")) {
+       } else if (!strncmp(prop->key, "SoundThemePath", strlen("SoundThemePath"))) {
                int str_len = sizeof(prop->value);
                sound_theme_elem->conf_file_path = strndup(prop->value, str_len);
-       } else if (MATCH(prop->key, "SoundThemeDefault")) {
-               if (MATCH(prop->value, "yes"))
+       } else if (!strncmp(prop->key, "SoundThemeDefault", strlen("SoundThemeDefault"))) {
+               if (!strncmp(prop->value, "yes", strlen("yes")))
                        sound_theme_elem->is_default = 1;
-               else if (MATCH(prop->value, "no"))
+               else if (!strncmp(prop->value, "no", strlen("no")))
                        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 (!MATCH("SoundTheme", result->section))
+       if (strncmp("SoundTheme", result->section, strlen("SoundTheme")))
                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 (MATCH(result->section, "Sound")) {
+       if (!strncmp(result->section, "Sound", strlen("Sound"))) {
                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 (!MATCH(result->section, "Sound"))
+       if (strncmp(result->section, "Sound", strlen("Sound")))
                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 (!MATCH("SoundPatternPriority", result->section))
+       if (strncmp("SoundPatternPriority", result->section, strlen("SoundPatternPriority")))
                return 0;
 
        sound_config_info = (GHashTable*)data;