fix the warning issues 67/242767/1
authordyamy-lee <dyamy.lee@samsung.com>
Fri, 28 Aug 2020 01:09:44 +0000 (10:09 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 1 Sep 2020 01:29:28 +0000 (10:29 +0900)
Change-Id: I7638271160cc6a31201b0c98a0e66ff0159b29c6

src/DSWaylandServer/DSWaylandProtocolTrace.cpp
src/DSWaylandServer/DSWaylandProtocolTracePrivate.h
tests/DSWaylandProtocolTrace-test.cpp

index 1d4194f..75d8583 100644 (file)
@@ -226,7 +226,7 @@ DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate()
 bool DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path)
 {
     bool ret = false;
-    char *argv[2];
+    const char *argv[2];
     int argc = 2;
 
     if(!rule_path || strlen(rule_path) <= 0)
@@ -330,7 +330,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
         ProtocolTrace_Rule_Set_Result result;
         const char * policy = argv[1]; //allow, deny
         char merge[8192] = {0,}, rule[8192] = {0,};
-        int i, index=0, size_rule, apply = 0;
+        int i, index=0, size_rule, apply = 0, size_merge;
 
         if(argc <3)
         {
@@ -354,8 +354,9 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
         protocol_arguments_merge(merge, sizeof(merge), argc -2, &(argv[2]));
 
         size_rule = sizeof(rule) -1;
+        size_merge = strlen(merge);
 
-        for(i=0; i<strlen(merge); i++)
+        for(i=0; i<size_merge; i++)
         {
             if(merge[i] == '\"' || merge[i] == '\'')
             {
@@ -372,8 +373,9 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
                 if(apply ==0)
                 {
                     const char * plus = "|| type=reply || type=error";
-                    int len = MIN(size_rule - index, strlen(plus));
-                    strncat(rule, plus, len);
+                    int size_plus = strlen(plus);
+                    int len = MIN(size_rule - index, size_plus);
+                    snprintf(rule, sizeof(rule), "%s", plus);
                     index += len;
                     if(index >size_rule)
                         return false;
@@ -506,7 +508,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename)
     while(pfs -fs < rule_len)
     {
         int i, new_argc =3;
-        char *new_argv[3] = {"add", };
+        const char *new_argv[3] = {"add", };
         char policy[64] = {0,};
         char rule[1024] = {0,};
 
@@ -543,7 +545,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename)
 
 bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protocol_Log *log)
 {
-    char *cmd = "";
+    const char *cmd = "";
 
     if(!rc)
         return false;
@@ -1262,7 +1264,7 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_re
     return PROTOCOLTRACE_RULE_SET_OK;
 }
 
-int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd)
+int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, const char *cmd)
 {
     ProtocolTrace_Validate_Args args = {type, target_id, name, pid, cmd};
     ProtocolTrace_Tree_Node *node;
@@ -1284,7 +1286,7 @@ int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_
     return default_policy == PROTOCOLTRACE_TYPE_ALLOW;
 }
 
-int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1)
+int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, const char *str1)
 {
     int result = strcasecmp(str2, str1);
 
@@ -1344,8 +1346,8 @@ int DSWaylandProtocolTracePrivate::rule_print_func(ProtocolTrace_Tree *tree, Pro
 {
     ProtocolTrace_Reply_Buffer *buffer = (ProtocolTrace_Reply_Buffer *)arg;
     char *reply = *buffer->reply;
-    int *len = buffer->len;
-    char *operators[] = {"==", "<", ">", "<=", ">=", "!=" };
+    //int *len = buffer->len;
+    const char *operators[] = {"==", "<", ">", "<=", ">=", "!=" };
     ProtocolTrace_Rule_Node *data;
 
     data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(node);
@@ -1415,14 +1417,15 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree,
         }
         if(msg)
         {
-            int min = MIN(sizeof(iface)-1, msg-args->name);
+            int size_iface = sizeof(iface) -1;
+            int min = MIN(size_iface, msg-args->name);
             strncpy(iface, args->name, min);
             iface[min] = '\0';
             msg++;
         }
         if(!strcasecmp(data->variable_name, "TYPE"))
         {
-            char *type_string;
+            const char *type_string;
             if(args->type == 0)
                 type_string = "REQUEST";
             else if(args->type == 1)
@@ -1440,7 +1443,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree,
         }
         else if(!strcasecmp(data->variable_name, "IFACE"))
         {
-            if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface))
+            if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, (const char *)iface))
                 data->result = PROTOCOLTRACE_RESULT_TRUE;
             else
                 data->result = PROTOCOLTRACE_RESULT_FALSE;
index 569b462..d387a9f 100644 (file)
@@ -31,7 +31,7 @@
 #include <wayland-util.h>
 #include <cstring>
 
-#define PATH_MAX 255 //tmp 255
+#define PATH_MAX 512
 
 #ifndef MAX
 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
@@ -210,7 +210,7 @@ typedef struct
     int target_id;
     const char *name;
     int pid;
-    char *cmd;
+    const char *cmd;
 } ProtocolTrace_Validate_Args;
 
 typedef struct
@@ -278,8 +278,8 @@ private:
     ProtocolTrace_Rule_Set_Result rulechecker_rule_add(_ProtocolTrace_Rule_Checker *rc, ProtocolTrace_Policy_Type policy, const char *rule_string);
     void rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc);
     ProtocolTrace_Rule_Set_Result rulechecker_rule_remove(ProtocolTrace_Rule_Checker *rc, int index);
-    static int rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd);
-    static int rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1);
+    static int rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, const char *cmd);
+    static int rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, const char *str1);
     const char * rulechecker_usage_print();
     static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg);
     static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg);
index 31201ff..3139fd4 100644 (file)
@@ -67,7 +67,7 @@ TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceUpdateRule)
         pTrace->init();
 
         int argc = 3;
-        char *argv[3];
+        const char *argv[3];
         argv[0] = "add";
         argv[1] = "ALLOW";
         argv[2] = "all";