correct typo error and defect 65/242765/1
authordyamy-lee <dyamy.lee@samsung.com>
Fri, 21 Aug 2020 09:32:45 +0000 (18:32 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 1 Sep 2020 01:29:26 +0000 (10:29 +0900)
Change-Id: Idb57323778c2cee9850a52681d7e8a676d541c44

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

index a4cfa29..30e8d02 100644 (file)
@@ -74,7 +74,8 @@ DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr)
          __canvas(nullptr),
          __dsBufferManager(nullptr),
          __dsAppinfoMgr(nullptr),
-         __dsWindowMgr(nullptr)
+         __dsWindowMgr(nullptr),
+         __protocolTrace(nullptr)
 
 {
        __eventLoop = DSEventLoop::getInstance();
@@ -170,8 +171,9 @@ void DSCompositorPrivate::__initializeWindowManager()
 void DSCompositorPrivate::__initializeProtocolTrace()
 {
        __protocolTrace = DSWaylandProtocolTrace::getInstance();
-       __protocolTrace->init();
-       __protocolTrace->enableProtocolTrace(true);
+       if(__protocolTrace){
+               if(__protocolTrace->init())
+                       __protocolTrace->enableProtocolTrace(true);
+       }
 }
-
 } // namespace display_server
index 97eaad0..9122a09 100644 (file)
@@ -93,9 +93,6 @@ const char *get_next_argument(const char *signature, struct argument_details *de
 DSWaylandProtocolTrace::DSWaylandProtocolTrace(DSObject *parent)
     : DS_INIT_PRIVATE_PTR(DSWaylandProtocolTrace)
 {
-    //init();
-    DS_GET_PRIV(DSWaylandProtocolTrace);
-    priv->__wlCompositor = DSWaylandCompositor::getInstance();
 }
 
 DSWaylandProtocolTrace::~DSWaylandProtocolTrace()
@@ -138,7 +135,6 @@ bool DSWaylandProtocolTrace::init(void)
     DS_GET_PRIV(DSWaylandProtocolTrace);
     bool ret = false;
     char *env_path = nullptr;
-    char tmp[PATH_MAX] = {0,};
 
     rc = priv->rulechecker_init();
 
@@ -150,11 +146,10 @@ bool DSWaylandProtocolTrace::init(void)
 
     if(env_path)
     {
-        //TODO: free env_path
-        DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path = %s", env_path);
-        //free(env_path);
+        char *tmp = strdup(env_path);
+        if(!tmp) return false;
+        free(tmp);
         env_path = nullptr;
-        DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path done.");
     }
     if(!ret) return ret;
 
@@ -164,13 +159,13 @@ bool DSWaylandProtocolTrace::init(void)
     DSLOG_DBG("DSWaylandProtocolTrace", "==================================================== trace file path = %s", env_path);
     ret = priv->protocol_trace_init(env_path);
     DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol trace init = %d", ret);
+
     if(env_path)
     {
-        //TODO: free env_path
-        DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path = %s", env_path);
-        //free(env_path);
+        char *tmp = strdup(env_path);
+        if(!tmp) return false;
+        free(tmp);
         env_path = nullptr;
-        DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path done.");
     }
     return ret;
 }
@@ -219,7 +214,7 @@ bool DSWaylandProtocolTrace::updateProtocolRule(const int argc, const char **arg
 DSWaylandProtocolTracePrivate::DSWaylandProtocolTracePrivate(DSWaylandProtocolTrace *p_ptr)
     : DSObjectPrivate(p_ptr), __p_ptr(p_ptr)
 {
-
+    __wlCompositor = DSWaylandCompositor::getInstance();
 }
 
 DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate()
@@ -229,27 +224,34 @@ DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate()
 
 bool DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path)
 {
+    bool ret = false;
     char *argv[2];
     int argc = 2;
 
     if(!rule_path || strlen(rule_path) <= 0)
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePrivate", "rule path is null");
         return false;
+    }
 
     argv[0] = "file";
     argv[1] = rule_path;
 
     DSLOG_DBG("DSWaylandProtocolTracePriv", "rule_path = %s", rule_path);
 
-    protocol_rule_set(argc, (const char**)&(argv[0]));
+    ret = protocol_rule_set(argc, (const char**)&(argv[0]));
 
-    return true;
+    return ret;
 }
 
 bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path)
 {
     DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_trace_init");
     if(!trace_path || strlen(trace_path) <= 0)
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePrivate", "trace path is null");
         return false;
+    }
 
     trace_env_path = trace_path;
     DSLOG_DBG("DSWaylandProtocolTracePriv", "saved trace path = %s", trace_env_path);
@@ -274,6 +276,38 @@ bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path)
     return true;
 }
 
+int DSWaylandProtocolTracePrivate::chk(const char *str)
+{
+    char *endptr;
+    int index = strtol(str, &endptr, 10);
+    if(errno == ERANGE)
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : overflow");
+        return -1;
+    }
+    if(errno != 0)
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : other error");
+        return -1;
+    }
+    if(endptr == 0)
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : non-numeric");
+        return -1;
+    }
+    if(*endptr != '\0')
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : non-numeric at end");
+        return -1;
+    }
+    if(isspace(*str))
+    {
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : space at beginning");
+        return -1;
+    }
+    return index;
+}
+
 bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char **argv)
 {
     DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_set");
@@ -361,7 +395,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
         }
         else if(result == PROTOCOLTRACE_RULE_SET_ERR_PARSE)
         {
-            DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: An error occured during parsing the rule [%s]", rule);
+            DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: An error occurred during parsing the rule [%s]", rule);
             return false;
         }
         DSLOG_INF("DSWaylandProtocolTracePriv", "The rule was successfully added");
@@ -398,13 +432,20 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
             }
             else
             {
-                int index = atoi(remove_idx);
-                DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index);
-
-                if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0)
-                    DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index);
+                int index = chk(remove_idx);
+                if(index == -1)
+                {
+                    DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : overflow");
+                }
                 else
-                    DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx);
+                {
+                    DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index);
+
+                    if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0)
+                        DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index);
+                    else
+                        DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx);
+                }
             }
         }
         rulechecker_rule_print(rc);
@@ -438,7 +479,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
         return true;
     }
 
-    DSLOG_ERR("DSWaylandProtocolTracePriv", "%s\nUnkown command : [%s] ", rulechecker_usage_print(), command);
+    DSLOG_ERR("DSWaylandProtocolTracePriv", "%s\nUnknown command : [%s] ", rulechecker_usage_print(), command);
 
     DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_rule_set");
 
@@ -454,7 +495,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename)
     fd = open(filename, O_RDONLY);
     if(fd<0)
     {
-        DSLOG_DBG("DSWaylandProtocolTracePriv", "failed: open '%s'", filename);
+        DSLOG_ERR("DSWaylandProtocolTracePriv", "failed: open '%s'", filename);
         return false;
     }
 
@@ -577,8 +618,7 @@ void DSWaylandProtocolTracePrivate::wl_protocol_cb_client_destroy(struct wl_list
         DSLOG_INF("DSWaylandProtocolTracePriv", "%s", strbuf);
 
     wl_list_remove(&listener->link);
-    //free(listener);
-    delete listener;
+    free(listener);
     listener = nullptr;
 }
 
@@ -593,6 +633,8 @@ void DSWaylandProtocolTracePrivate::protocol_client_destroy_listener_reg(struct
 
     destroy_listener = (struct wl_listener *)calloc(1, sizeof(wl_listener));
     //EINA_SAFETY_ON_NULL_RETURN(destroy_listener);
+    if(!destroy_listener)
+        return;
 
     destroy_listener->notify = wl_protocol_cb_client_destroy;
     wl_client_add_destroy_listener(client, destroy_listener);
@@ -693,6 +735,8 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_create_node(Prot
 {
     ProtocolTrace_Tree_Node *node = (ProtocolTrace_Tree_Node*) calloc(1, sizeof(ProtocolTrace_Tree_Node) + tree->size);
     // enia safety
+    if(!node)
+        return nullptr;
 
     node->left = nullptr;
     node->right = nullptr;
@@ -704,6 +748,8 @@ ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::bintree_create_tree(int size)
 {
     ProtocolTrace_Tree *tree = (ProtocolTrace_Tree *)calloc(1, sizeof(ProtocolTrace_Tree) + size);
     // eina safety
+    if(!tree)
+        return nullptr;
 
     tree->size = size;
     tree->head = nullptr;
@@ -714,8 +760,7 @@ void DSWaylandProtocolTracePrivate::bintree_destroy_tree(ProtocolTrace_Tree *tre
 {
     if(tree->head)
         bintree_remove_node_recursive(tree->head);
-    //free(tree);
-    delete tree;
+    free(tree);
 }
 
 ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_head(ProtocolTrace_Tree *tree)
@@ -779,8 +824,7 @@ int DSWaylandProtocolTracePrivate::bintree_postorder_traverse_recursive(Protocol
 
 void DSWaylandProtocolTracePrivate::bintree_remove_node(ProtocolTrace_Tree_Node *node)
 {
-    //free(node);
-    delete node;
+    free(node);
 }
 
 void DSWaylandProtocolTracePrivate::bintree_remove_node_recursive(ProtocolTrace_Tree_Node *node)
@@ -919,7 +963,7 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P
         goto fail;
 
     node = bintree_create_node(tree);
-    //eina safty
+    //eina safety
 
     data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node);
 
@@ -981,6 +1025,7 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P
     parser_token_process(token);
 
     return node;
+
     fail:
         if(node)
             bintree_remove_node_recursive(node);
@@ -1093,8 +1138,7 @@ void DSWaylandProtocolTracePrivate::rulechecker_destroy(ProtocolTrace_Rule_Check
     for(i=rc->count-1; i>=0; i--)
         rulechecker_rule_remove(rc,i);
 
-    //free(rc);
-    delete rc;
+    free(rc);
 }
 
 ProtocolTrace_Rule_Checker *DSWaylandProtocolTracePrivate::rulechecker_init()
@@ -1147,8 +1191,10 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_ad
 
 void DSWaylandProtocolTracePrivate::rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc)
 {
-    char *reply;
-    int *len;
+    char tmpReply[4096];
+    int tmpLen = sizeof(tmpReply);
+    char *reply = tmpReply;
+    int *len = &tmpLen;
     ProtocolTrace_Reply_Buffer buffer = {&reply, len};
     int i;
 
@@ -1322,11 +1368,12 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree,
     }
     else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_DATA)
     {
-        char iface[64];
+        char iface[64] = {0,};
         char *msg = nullptr;
+        int colon = atoi(":");
 
         if(args->name)
-            msg = ":";//index(args->name, ":");
+            msg = (char *) index(args->name, colon);
         if(msg)
         {
             int min = MIN(sizeof(iface)-1, msg-args->name);
@@ -1354,7 +1401,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree,
         }
         else if(!strcasecmp(data->variable_name, "IFACE"))
         {
-            if(msg && rulechecker_string_compare(data->comparer, data->value.string, iface))
+            if(msg && !iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface))
                 data->result = PROTOCOLTRACE_RESULT_TRUE;
             else
                 data->result = PROTOCOLTRACE_RESULT_FALSE;
index 8c22087..ffecf2d 100644 (file)
@@ -283,6 +283,7 @@ private:
     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);
+    int chk(const char *str);
 };
 
 }
index 63d0e67..31201ff 100644 (file)
@@ -30,7 +30,9 @@ class DSWaylandProtocolTraceTest : public ::testing::Test
 {
 public:
     void SetUp(void) override
-    {}
+    {
+        setenv("XDG_RUNTIME_DIR", "/run", 1);
+    }
     void TearDown(void) override
     {}