From: nshero.lee Date: Tue, 30 Jan 2018 06:06:07 +0000 (+0900) Subject: Fixed TPLDOCKER-421 issue regarding garbage data in proxy value X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fdsm%2Ffeature;p=platform%2Fcore%2Fsystem%2Fsetup-adaptor.git Fixed TPLDOCKER-421 issue regarding garbage data in proxy value 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 --- diff --git a/packaging/setup-adaptor.spec b/packaging/setup-adaptor.spec index bb6d805..d036ed4 100644 --- a/packaging/setup-adaptor.spec +++ b/packaging/setup-adaptor.spec @@ -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 diff --git a/src/input_file.c b/src/input_file.c index 4004024..059c3cc 100644 --- a/src/input_file.c +++ b/src/input_file.c @@ -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); diff --git a/test/config.json b/test/config.json index 1799a57..1008d58 100644 --- a/test/config.json +++ b/test/config.json @@ -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":"" +}