From: hwajeong.son Date: Mon, 1 Oct 2018 10:45:40 +0000 (+0900) Subject: Fixed SVACE bug X-Git-Tag: submit/tizen/20181002.025635~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28139283550d7ad0d2ef27dfdf3876c536c9143e;p=platform%2Fcore%2Fsystem%2Fsetup-adaptor.git Fixed SVACE bug Locally, the codes are checked with SVACE tool and fixed critical and major issues --- diff --git a/src/input_file.c b/src/input_file.c index 78f75a3..3ec9593 100755 --- a/src/input_file.c +++ b/src/input_file.c @@ -187,15 +187,15 @@ static char *json_get_string_from_obj(json_object * inputObj, char *key) static void print_config_network_static_info(sa_network_static_s * staticInfo) { if (staticInfo != NULL) { - if (staticInfo->ipAddress != NULL) + if (strlen(staticInfo->ipAddress) > 0) _D("static::ipAddress[%s]"); - if (staticInfo->netmask != NULL) + if (strlen(staticInfo->netmask) > 0) _D("static::netmask[%s]"); - if (staticInfo->defaultGateway != NULL) + if (strlen(staticInfo->defaultGateway) > 0) _D("static::defaultGateway[%s]"); - if (staticInfo->primaryDnsServer != NULL) + if (strlen(staticInfo->primaryDnsServer) > 0) _D("static::primaryDnsServer[%s]"); - if (staticInfo->secondaryDnsServer != NULL) + if (strlen(staticInfo->secondaryDnsServer) > 0) _D("static::secondaryDnsServer[%s]"); } } @@ -210,10 +210,8 @@ static void print_network_config(sa_network_s * network) if (wifi != NULL) { _D("Network::wifi::enabled[%d]", wifi->enabled); _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled); - if (wifi->ssid != NULL) - _D("Network::wifi::ssid[%s]", wifi->ssid); - if (wifi->password != NULL) - _D("Network::wifi::password[%s]", wifi->password); + _D("Network::wifi::ssid[%s]", wifi->ssid); + _D("Network::wifi::password[%s]", wifi->password); if (wifi->dhcpEnabled == 0) print_config_network_static_info(wifi->staticInfo); @@ -243,8 +241,7 @@ static void print_system_config(sa_system_s * systemData) static void print_config_info(sa_config_s * config) { if (config != NULL) { - if (config->version != NULL) - _D("Version [%s]", config->version); + _D("Version [%s]", config->version); if (config->networkData) print_network_config(config->networkData); @@ -270,35 +267,36 @@ static int __parse_network_static_info(json_object * inputObj, sa_network_static ipAddress = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_IPADDRESS); if (ipAddress != NULL) { _D("ipaddress = %s", ipAddress); - memcpy(staticInfo->ipAddress, ipAddress, strlen(ipAddress)); + + memcpy(staticInfo->ipAddress, ipAddress, MIN(strlen(ipAddress), sizeof(staticInfo->ipAddress) - 1)); free(ipAddress); ipAddress = NULL; } //netmask netmask = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_NETMASK); if (netmask != NULL) { - memcpy(staticInfo->netmask, netmask, strlen(netmask)); + memcpy(staticInfo->netmask, netmask, MIN(strlen(netmask), sizeof(staticInfo->netmask) - 1)); free(netmask); netmask = NULL; } //defaultGateway defaultGateway = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY); if (defaultGateway != NULL) { - memcpy(staticInfo->defaultGateway, defaultGateway, strlen(defaultGateway)); + memcpy(staticInfo->defaultGateway, defaultGateway, MIN(strlen(defaultGateway), sizeof(staticInfo->defaultGateway) - 1)); free(defaultGateway); defaultGateway = NULL; } //primaryDnsServer primaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER); if (primaryDnsServer != NULL) { - memcpy(staticInfo->primaryDnsServer, primaryDnsServer, strlen(primaryDnsServer)); + memcpy(staticInfo->primaryDnsServer, primaryDnsServer, MIN(strlen(primaryDnsServer), sizeof(staticInfo->primaryDnsServer) - 1)); free(primaryDnsServer); primaryDnsServer = NULL; } //secondaryDnsServer secondaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER); if (secondaryDnsServer != NULL) { - memcpy(staticInfo->secondaryDnsServer, secondaryDnsServer, strlen(secondaryDnsServer)); + memcpy(staticInfo->secondaryDnsServer, secondaryDnsServer, MIN(strlen(secondaryDnsServer), sizeof(staticInfo->secondaryDnsServer) - 1)); free(secondaryDnsServer); secondaryDnsServer = NULL; } @@ -637,11 +635,13 @@ void sa_inputfile_release_resource(sa_config_s * config) void sa_inputfile_remove(void) { - if (remove(CONFIG_FILE) != 0) - _E("Can't remove file{%s}! %s", CONFIG_FILE, strerror(errno)); - else - _D("file removed successfully..{%s}", CONFIG_FILE); + char buff[256]; + if (remove(CONFIG_FILE) != 0) { + if (strerror_r(errno, buff, sizeof(buff)) == 0) + _E("Can't remove file{%s}! %s", CONFIG_FILE, buff); + } else + _D("file removed successfully..{%s}", CONFIG_FILE); } void sa_inputfile_clear_completion_flag(void) @@ -660,6 +660,7 @@ void sa_inputfile_clear_completion_flag(void) void sa_inputfile_set_completion_flag(sa_file_config_e config_type) { int fd; + char buff[256]; switch (config_type) { case SA_FILE_CONFIG_SYSTEM: @@ -676,8 +677,11 @@ void sa_inputfile_set_completion_flag(sa_file_config_e config_type) break; } - if (fd == -1) - _E("Can't create file for (%d)! %s", config_type, strerror(errno)); + if (fd == -1) { + if (strerror_r(errno, buff, sizeof(buff)) == 0) + _E("Can't create file for {%d}! %s", config_type, buff); + } else + close(fd); } // return TRUE if set diff --git a/src/setup_network.c b/src/setup_network.c index dfbe151..15161ee 100755 --- a/src/setup_network.c +++ b/src/setup_network.c @@ -413,34 +413,34 @@ static int __eth_update_ip_info(sa_eth_s * info, connection_profile_h profile, c char input_str[100] = { 0, }; _D("ipaddress =%s", info->staticInfo->ipAddress); - if (info->staticInfo->ipAddress != NULL) { + if (strlen(info->staticInfo->ipAddress) > 0) { rv = connection_profile_set_ip_address(profile, address_family, info->staticInfo->ipAddress); if (rv != CONNECTION_ERROR_NONE) return -1; } _D("netmask =%s", info->staticInfo->netmask); - if (info->staticInfo->netmask != NULL) { + if (strlen(info->staticInfo->netmask) > 0) { rv = connection_profile_set_subnet_mask(profile, address_family, info->staticInfo->netmask); if (rv != CONNECTION_ERROR_NONE) return -1; } - if (info->staticInfo->defaultGateway != NULL) { + if (strlen(info->staticInfo->defaultGateway) > 0) { rv = connection_profile_set_gateway_address(profile, address_family, info->staticInfo->defaultGateway); if (rv != CONNECTION_ERROR_NONE) return -1; _D("gateway =%s", info->staticInfo->defaultGateway); } - if (info->staticInfo->primaryDnsServer != NULL) { + if (strlen(info->staticInfo->primaryDnsServer) > 0) { rv = connection_profile_set_dns_address(profile, 1, address_family, info->staticInfo->primaryDnsServer); if (rv != CONNECTION_ERROR_NONE) return -1; _D("DNS 1 =%s", info->staticInfo->primaryDnsServer); - if (info->staticInfo->secondaryDnsServer != NULL) { + if (strlen(info->staticInfo->secondaryDnsServer) > 0) { rv = connection_profile_set_dns_address(profile, 2, address_family, info->staticInfo->secondaryDnsServer); if (rv != CONNECTION_ERROR_NONE) return -1;