Fix Svace issues in wifi_test.c
authorSeongil Hahm <seongil.hahm@samsung.com>
Thu, 14 Sep 2017 09:35:15 +0000 (02:35 -0700)
committerSeongil Hahm <seongil.hahm@samsung.com>
Thu, 14 Sep 2017 09:35:15 +0000 (02:35 -0700)
1. use strncat instead of strcat.
2. use snprintf instead of sprintf
3. close socket fd when send() fails.

apps/examples/wifi_test/wifi_test.c

index 4f670d0..473aae6 100644 (file)
@@ -204,15 +204,16 @@ int wifi_test_proc(int argc, char *argv[])
                memset(payload, 0, BUF_MAX_SIZE);
 
                printScanResult(scan_info);
-               sprintf(payload, "/%s|", DEVICE_NAME);
+               snprintf(payload, BUF_MAX_SIZE, "/%s|", DEVICE_NAME);
                for (i = 0; i < aps_cnt; i++) {
                        sprintf(buf, "%02d:%d/", g_aps[i].id, g_aps[i].rssi);
-                       strcat(payload, buf);
+                       strncat(payload, buf, strlen(buf));
                }
                printf("[WiFi] PAYLOAD : %s\n", payload);
                if (sendto(fd, payload, strlen(payload), 0, (struct sockaddr *)&dest, sizeof(struct sockaddr_in)) == -1) {
                        printf("[WiFi] Failed to sendto UDP.\n");
                        ret = -1;
+                       closesocket(fd);
                        goto error_out;
                }
                /* Type in code to free WiFi scan data. Do check and