Fix buffer overflow 02/223602/2 accepted/tizen/unified/20200205.125340 submit/tizen/20200204.080737
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 31 Jan 2020 06:17:02 +0000 (15:17 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 31 Jan 2020 06:45:44 +0000 (15:45 +0900)
WGID-423439

Change-Id: I794e900497d91622dcf05175cd414336f2aed955

test/vpn_test.c

index 0c28aed878233a0b40f24e20cde5b51362d4397a..804d6f8f1c04f5f4ac1f53159551a2bec5bc3ebf 100755 (executable)
@@ -39,6 +39,8 @@
 #define CLIENT_PRIVATE_KEY "client-private.PEM"
 #endif
 
+#define MAX_USER_INPUT_LEN 200
+
 gboolean test_thread(GIOChannel *source,
                        GIOCondition condition,
                        gpointer data);
@@ -317,8 +319,11 @@ static void _test_get_vpn_handle(vpn_h *handle_ptr)
 
 static void _test_get_user_input(char *buf, char *what)
 {
+       char format[12];
+
+       snprintf(format, 12, " %%%d[^\n]s", MAX_USER_INPUT_LEN);
        printf("Please ENTER %s:", what);
-       if (scanf(" %[^\n]s", buf) < 0)
+       if (scanf(format, buf) < 0)
                printf("Error in Reading the data to Buffer\n");
 }
 
@@ -372,7 +377,7 @@ int test_vpn_settings_init(void)
 int test_vpn_settings_add(void)
 {
        int rv = 0;
-       char buf[100];
+       char buf[MAX_USER_INPUT_LEN + 1];
 
        _test_get_user_input(&buf[0], "Type");
        rv = vpn_settings_set_type(&buf[0]);
@@ -431,8 +436,8 @@ int test_vpn_settings_deinit(void)
 int test_vpn_settings_set_specific(void)
 {
        int rv = 0;
-       char key[100];
-       char value[200];
+       char key[MAX_USER_INPUT_LEN + 1];
+       char value[MAX_USER_INPUT_LEN + 1];
 
        _test_get_user_input(&key[0], "Key");
        _test_get_user_input(&value[0], "Value");