power: Use strncpy to avoid the potential problem 00/289800/4 accepted/tizen/unified/20230316.101444
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 14 Mar 2023 08:54:34 +0000 (17:54 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Wed, 15 Mar 2023 01:43:34 +0000 (10:43 +0900)
sscanf function is detected as risky function in static analysis.
Thus, change the sscanf function to strncpy function.

Change-Id: I44b883eeaeea401dc251577f2bbced4f9ee8c72c
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/power/power-boot.c

index 74ec729..0f39f4a 100644 (file)
@@ -48,8 +48,8 @@ static struct trans_info init_ti = {
 };
 
 static struct boot_condition {
-       char reason[64];
-       char mode[64];
+       char reason[128];
+       char mode[128];
 } bc = { "unknown", "normal" };
 
 static guint sig_id[2] = {0, 0};
@@ -159,9 +159,9 @@ static int parse_matching_boot_condition(const struct parse_result *result, void
 
        SYS_G_LIST_FOREACH(result->props, elem, prop) {
                if (MATCH(prop->key, "BootReason"))
-                       sscanf(prop->value, "%s", config_bc.reason);
+                       strncpy(config_bc.reason, prop->value, sizeof(prop->value) - 1);
                else if (MATCH(prop->key, "BootMode"))
-                       sscanf(prop->value, "%s", config_bc.mode);
+                       strncpy(config_bc.mode, prop->value, sizeof(prop->value) - 1);
        }
 
        if (MATCH(bc.reason, config_bc.reason) && MATCH(bc.mode, config_bc.mode))