Fix CHECKED_RETURN Major detect 93/324393/6
authortranthanhtung2001 <tran.tung@samsung.com>
Fri, 16 May 2025 08:13:20 +0000 (15:13 +0700)
committertranthanhtung2001 <tran.tung@samsung.com>
Mon, 19 May 2025 05:56:15 +0000 (12:56 +0700)
Change-Id: Ia9f426e64b26b4c135b2281697ab6838e3670296

test/tc-common.c

index d2d5eaf4e791489328d7198c9346c135a46d526c..097a6b14198293e9c5c3d0c018b882693082ac74 100644 (file)
@@ -140,6 +140,18 @@ char* __get_privilege_type_string(privilege_manager_privilege_type_e type)
        }
 }
 
+bool __check_strlcat(char *dest, const char *src, const int size)
+{
+       return (g_strlcat(dest, src, size) >= (gsize) size) ? true : false;
+}
+
+void __print_warning_msg_truncated()
+{
+       __color_to_bold_yellow();
+       printf("\nWarning: Concated message was truncated\n");
+       __color_to_origin();
+}
+
 /* shows error_message returned by privilege_manager_verify_privilege() */
 void __print_error_message(char *error_message)
 {
@@ -152,23 +164,30 @@ void __print_error_message(char *error_message)
        memset(err_type, 0, err_type_size*sizeof(char));
 
        if (strstr(error_message, "DEPRECATED") != NULL)
-               g_strlcat(err_type, "PRVMGR_ERR_DEPRECATED_PRIVILEGE ", err_type_size);
+               if (__check_strlcat(err_type, "PRVMGR_ERR_DEPRECATED_PRIVILEGE ", err_type_size))
+                       __print_warning_msg_truncated();
 
        if (strstr(error_message, "NO_EXIST") != NULL)
-               g_strlcat(err_type, "PRVMGR_ERR_NO_EXIST_PRIVILEGE ", err_type_size);
+               if (__check_strlcat(err_type, "PRVMGR_ERR_NO_EXIST_PRIVILEGE ", err_type_size))
+                       __print_warning_msg_truncated();
 
        if (strstr(error_message, "MISMATCHED") != NULL)
-               g_strlcat(err_type, "PRVMGR_ERR_MISMACHED_PRIVILEGE_LEVEL ", err_type_size);
+               if (__check_strlcat(err_type, "PRVMGR_ERR_MISMACHED_PRIVILEGE_LEVEL ", err_type_size))
+                       __print_warning_msg_truncated();
 
        if (strstr(error_message, "INVALID_PARAMETER") != NULL)
-               g_strlcat(err_type, "PRVMGR_ERR_INVALID_PARAMETER ", err_type_size);
+               if (__check_strlcat(err_type, "PRVMGR_ERR_INVALID_PARAMETER ", err_type_size))
+                       __print_warning_msg_truncated();
 
        if (strstr(error_message, "banned") != NULL)
-               g_strlcat(err_type, "PRVMGR_ERR_USING_BANNED_PRIVILEGE ", err_type_size);
+               if (__check_strlcat(err_type, "PRVMGR_ERR_USING_BANNED_PRIVILEGE ", err_type_size))
+                       __print_warning_msg_truncated();
 
        if (strlen(err_type) == 0) {
                fail_cnt++;
-               g_strlcat(err_type, "test failed - unknown error type", err_type_size);
+               if (__check_strlcat(err_type, "test failed - unknown error type", err_type_size))
+                       __print_warning_msg_truncated();
+
                __color_to_red();
        } else {
                __color_to_blue();