Fixed coverity issues
[platform/core/connectivity/net-config.git] / src / utils / network-accessibility.c
index 5cf23b3..df1312c 100755 (executable)
@@ -63,14 +63,14 @@ struct internet_params {
        gboolean request_started;
 };
 
-const static char* url_list[] = {
+static const char* url_list[] = {
         "www.google.com",
         "www.msn.com",
         "www.yahoo.com",
         "m.google.com",
         "www.amazon.com",
         "www.youtube.com"
- };
+};
 
 #define URL_LIST_NUM           6
 
@@ -100,6 +100,7 @@ static void __netconfig_update_internet_status(unsigned char *reply)
         * then no Internet is available */
        char *temp = NULL;
        is_internet_available = FALSE;
+       char *saveptr = NULL;
 
        if (NULL != reply) {
                if ((NULL != g_strrstr((char*)reply, "HTTP/1.1 200")) &&
@@ -108,7 +109,7 @@ static void __netconfig_update_internet_status(unsigned char *reply)
                } else if (NULL != g_strrstr((char*)reply, "HTTP/1.1 302")) {
                        DBG("302:: Internet is un-available");
                } else if ((temp = g_strrstr((char*)reply, "Location:")) != NULL) {
-                       char * location = strtok(temp, "\r");
+                       char * location = strtok_r(temp, "\r", &saveptr);
                        if (location != NULL) {
                                DBG("%s", location);
                                if (redirect_url1 == NULL)
@@ -144,7 +145,7 @@ static gboolean __netconfig_data_activity_timeout(gpointer data)
 {
        DBG("Timer timed-out");
        enum netconfig_internet_check_state prev_state = (enum netconfig_internet_check_state)GPOINTER_TO_INT(data);
-       INFO("Prev_state: state=%d (1:dns check / 2:packet check)",prev_state);
+       INFO("Prev_state: state=%d (1:dns check / 2:packet check)", prev_state);
 
        if (net_params == NULL)
                return FALSE;
@@ -290,7 +291,7 @@ static gboolean __send_data_event(GIOChannel *channel,
        if (net_params->header_done == TRUE)
                return FALSE;
 
-       n = send(fd, request_data, strlen(request_data), 0);
+       n = send(fd, request_data, strlen(request_data), MSG_NOSIGNAL);
        DBG("Sent %d bytes", n);
 
        if (n < 0) {
@@ -368,7 +369,7 @@ static void __netconfig_connect_sockets(void)
        __internet_check_state(INTERNET_CHECK_STATE_PACKET_CHECK);
        return;
 
-       cleanup:
+cleanup:
        __internet_check_state(INTERNET_CHECK_STATE_NONE);
 }
 
@@ -389,9 +390,8 @@ static void __netconfig_obtain_host_ip_addr_cb(GObject *src,
 
        list = g_resolver_lookup_by_name_finish((GResolver *)src, res, &error);
        if (error != NULL) {
-               if (error->code == G_IO_ERROR_CANCELLED) {
+               if (error->code == G_IO_ERROR_CANCELLED)
                        ERR("G_IO_ERROR_CANCELLED is called[%s]", error->message);
-               }
                g_error_free(error);
        }
 
@@ -432,6 +432,7 @@ cleanup:
 gboolean __netconfig_obtain_host_ip_addr(void)
 {
        char *host, *addr, *port;
+       char *saveptr = NULL;
 
        if (net_params == NULL)
                return FALSE;
@@ -471,7 +472,7 @@ gboolean __netconfig_obtain_host_ip_addr(void)
                if (host == NULL)
                        goto cleanup;
 
-               addr = strtok(host, ":");
+               addr = strtok_r(host, ":", &saveptr);
                if (addr == NULL)
                        goto cleanup;
 
@@ -520,9 +521,8 @@ void netconfig_check_internet_accessibility(void)
        is_internet_available = FALSE;
 
        /* If the host IP is resolved, directly go for connecting to sockets*/
-       if (__netconfig_obtain_host_ip_addr() == TRUE) {
+       if (__netconfig_obtain_host_ip_addr() == TRUE)
                __netconfig_connect_sockets();
-       }
 }
 
 void netconfig_stop_internet_check(void)