Fixed TPLDOCKER-421 issue regarding garbage data in proxy value 73/168673/3 dsm/feature
authornshero.lee <nshero.lee@samsung.com>
Tue, 30 Jan 2018 06:06:07 +0000 (15:06 +0900)
committernshero.lee <nshero.lee@samsung.com>
Wed, 7 Feb 2018 00:26:12 +0000 (09:26 +0900)
When the value of proxy is empty, garbage date is written in environment file
Once check the value and do memset after allocation.
Also add the memset code all cases after malloc

Change-Id: Ia01f6d9f4eb74553662c310ecfeb9bdf6296ea49
Signed-off-by: nshero.lee <nshero.lee@samsung.com>
packaging/setup-adaptor.spec
src/input_file.c
test/config.json

index bb6d805ba48546fbfefffcb1e8d9c3f33b596d99..d036ed4068dbfa5ebec945380ae3774f7d284562 100644 (file)
@@ -1,6 +1,6 @@
 Name:       setup-adaptor
 Summary:    Provide network and system data setting daemon
-Version:    0.4.1
+Version:    0.4.2
 Release:    0
 Group:      System & System Tools
 ExclusiveArch: armv7l
index 40040243076a7637b292ec38f1114230ab773e2a..059c3cc84930cfc8666163b62a9653a872cec4ec 100644 (file)
@@ -79,6 +79,7 @@ static void *__config_main_loop(void *arg)
        buffer = (char *) malloc(EVENT_BUF_LEN);
 
        if (buffer != NULL) {
+               memset(buffer, 0x00, EVENT_BUF_LEN);
                // Start callack
                _D("Registerd Callback Triggered");
                callback(SA_FILE_STATE_REGISTERED, NULL, NULL);
@@ -314,6 +315,8 @@ static int __parse_network_static_info(json_object * inputObj, sa_network_static
                _D("__parse_network_static_info input error");
                return -1;
        }
+
+       memset(staticInfo, 0x00, sizeof(sa_network_static_s));
        //ipAddress
        ipAddress = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_IPADDRESS);
        if (ipAddress != NULL) {
@@ -363,6 +366,8 @@ static int __parse_network_eth(json_object * inputObj, sa_eth_s * eth)
                _D("__parse_network_eth input error");
                return -1;
        }
+
+       memset(eth, 0x00, sizeof(sa_eth_s));
        // enabled
        eth->enabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_ENABLED);
 
@@ -389,6 +394,8 @@ static int __parse_network_wifi(json_object * inputObj, sa_wifi_s * wifi)
                _D("__parse_network_wifi input error");
                return -1;
        }
+
+       memset(wifi, 0x00, sizeof(sa_wifi_s));
        // enabled
        wifi->enabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_ENABLED);
 
@@ -441,6 +448,7 @@ static int __parse_network_data(json_object * inputObj, sa_config_s * setupConfi
 
        setupConfig->networkData = (sa_network_s *) malloc(sizeof(sa_network_s));
        if (setupConfig->networkData != NULL) {
+               memset(setupConfig->networkData, 0x00, sizeof(sa_network_s));
                //parse wifi
                if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_WIFI, &wifiObj)) {
                        if (json_object_get_type(wifiObj) == json_type_object) {
@@ -488,6 +496,8 @@ static int __parse_system_insecure_registries(json_object * inputObj, sa_dockerd
                return -1;
        }
 
+       memset(opt, 0x00, sizeof(sa_dockerd_opt_s));
+
        opt->count = json_object_array_length(inputObj);
        if (opt->count > 0) {
                opt->insecureRegistries = (char **) malloc(sizeof(char *) * opt->count);
@@ -514,6 +524,8 @@ static int __parse_system_insecure_registries(json_object * inputObj, sa_dockerd
                        ret = -1;
                        _E("malloc failed for inscureRegistries first");
                }
+       } else {
+               _D("Insecure registries is empty");
        }
 
        return ret;
@@ -533,15 +545,18 @@ static int __parse_system_data(json_object * inputObj, sa_config_s * setupConfig
        setupConfig->systemData = (sa_system_s *) malloc(sizeof(sa_system_s));
 
        if (setupConfig->systemData != NULL) {
+               memset(setupConfig->systemData, 0x00, sizeof(sa_system_s));
                //httpProxy
                httpProxy = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXY);
                if (httpProxy != NULL) {
-                       setupConfig->systemData->proxy = (sa_proxy_s *) malloc(sizeof(sa_proxy_s));
-                       if (setupConfig->systemData->proxy != NULL) {
-                               memcpy(setupConfig->systemData->proxy->httpProxy, httpProxy, MIN(strlen(httpProxy), sizeof(setupConfig->systemData->proxy->httpProxy) - 1));
-                       } else {
-                               ret = -1;
-                               _D("malloc fail setupConfig->systemData->proxy");
+                       if (strlen(httpProxy) > 0) {
+                               setupConfig->systemData->proxy = (sa_proxy_s *) malloc(sizeof(sa_proxy_s));
+                               if (setupConfig->systemData->proxy != NULL) {
+                                       memcpy(setupConfig->systemData->proxy->httpProxy, httpProxy, MIN(strlen(httpProxy), sizeof(setupConfig->systemData->proxy->httpProxy) - 1));
+                               } else {
+                                       ret = -1;
+                                       _D("malloc fail setupConfig->systemData->proxy");
+                               }
                        }
                }
 
@@ -549,9 +564,9 @@ static int __parse_system_data(json_object * inputObj, sa_config_s * setupConfig
                if (json_object_object_get_ex(inputObj, SA_CONFIG_SYSTEMDATA_INSECURE_REGISTRIES, &arrayObj)) {
                        if (json_object_get_type(arrayObj) == json_type_array) {
                                setupConfig->systemData->dockerdOpt = (sa_dockerd_opt_s *) malloc(sizeof(sa_dockerd_opt_s));
-                               if (setupConfig->systemData->dockerdOpt != NULL)
+                               if (setupConfig->systemData->dockerdOpt != NULL) {
                                        ret = __parse_system_insecure_registries(arrayObj, setupConfig->systemData->dockerdOpt);
-                               else {
+                               else {
                                        _E("malloc failed setupConfig->systemData->dockerdOpt");
                                        ret = -1;
                                }
@@ -660,8 +675,8 @@ int __create_dockerd_opt(sa_dockerd_opt_s * opt, char **value)
        registryObj = json_object_new_object();
        arrayObj = json_object_new_array();
 
-       if (registryObj != NULL && arrayObj != NULL) {
-               if (opt->count > 0) {
+       if (opt->count > 0) {
+               if (registryObj != NULL && arrayObj != NULL) {
                        for (ulIndex = 0; ulIndex < opt->count; ulIndex++) {
                                // string add in arrayObj
                                /*Creating json strings*/
@@ -672,21 +687,22 @@ int __create_dockerd_opt(sa_dockerd_opt_s * opt, char **value)
                                }
                        }
                        json_object_object_add(registryObj, SA_CONFIG_SYSTEMDATA_INSECURE_REGISTRIES, arrayObj);
-               }
 
-               buf = json_object_to_json_string_ext(registryObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+                       buf = json_object_to_json_string_ext(registryObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
 
-               if (buf != NULL) {
-                       *value = (char *)malloc(strlen(buf)+1);
-                       if (*value != NULL) {
-                               buf_len = strlen(buf);
-                               memset(*value, 0x00, strlen(buf)+1);
-                               memcpy(*value, buf, strlen(buf) + 1);
-                               _D("service create json:[%s]", *value);
+                       if (buf != NULL) {
+                               *value = (char *)malloc(strlen(buf)+1);
+                               if (*value != NULL) {
+                                       buf_len = strlen(buf);
+                                       memset(*value, 0x00, strlen(buf)+1);
+                                       memcpy(*value, buf, strlen(buf) + 1);
+                                       _D("service create json:[%s]", *value);
+                               }
                        }
-               }
-       } else
-               _D("empty object is not created");
+               } else
+                       _D("empty object is not created");
+       }
+
        if (registryObj != NULL)
                json_object_put(registryObj);
 
index 1799a57d2fffccc77b4a9ee65046f8d02b3b61fe..1008d583d8d1905448978aa3b18061fead7d0b70 100644 (file)
@@ -2,5 +2,5 @@
 "version":"0.1",
 "wifi":{"ssid":"docker","password":"dockerdocker","enabled":true,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDNSServer":"127.0.0.1","secondaryDNSServer":"127.0.0.1"},
 "ethernet":{"enabled":false,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDnsServer":"127.0.0.1","secondaryDnsServer":"127.0.0.1"},
-"insecure-registries":["docker.sec.samsung.net:5000","10.113.171.118:443"],"httpProxy":"10.112.1.184:8080"
-}
\ No newline at end of file
+"insecure-registries":[],"httpProxy":""
+}