]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Remove strcpy from unit tests.
authorArlo Breault <arlolra@gmail.com>
Sat, 11 May 2013 21:06:22 +0000 (14:06 -0700)
committerNick Mathewson <nickm@torproject.org>
Sun, 12 May 2013 03:33:41 +0000 (23:33 -0400)
See #8790.

src/test/test_pt.c
src/test/test_util.c

index 80707f437951ed0fd3f5371c42370a12f45debfd..d4cc0ae97b5d622b68d87ed24d498b4b9331e5dc 100644 (file)
@@ -28,58 +28,58 @@ test_pt_parsing(void)
   mp->transports = smartlist_new();
 
   /* incomplete cmethod */
-  strcpy(line,"CMETHOD trebuchet");
+  strlcpy(line,"CMETHOD trebuchet",sizeof(line));
   test_assert(parse_cmethod_line(line, mp) < 0);
 
   reset_mp(mp);
 
   /* wrong proxy type */
-  strcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999");
+  strlcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999",sizeof(line));
   test_assert(parse_cmethod_line(line, mp) < 0);
 
   reset_mp(mp);
 
   /* wrong addrport */
-  strcpy(line,"CMETHOD trebuchet socks4 abcd");
+  strlcpy(line,"CMETHOD trebuchet socks4 abcd",sizeof(line));
   test_assert(parse_cmethod_line(line, mp) < 0);
 
   reset_mp(mp);
 
   /* correct line */
-  strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999");
+  strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
   test_assert(parse_cmethod_line(line, mp) == 0);
   test_assert(smartlist_len(mp->transports));
 
   reset_mp(mp);
 
   /* incomplete smethod */
-  strcpy(line,"SMETHOD trebuchet");
+  strlcpy(line,"SMETHOD trebuchet",sizeof(line));
   test_assert(parse_smethod_line(line, mp) < 0);
 
   reset_mp(mp);
 
   /* wrong addr type */
-  strcpy(line,"SMETHOD trebuchet abcd");
+  strlcpy(line,"SMETHOD trebuchet abcd",sizeof(line));
   test_assert(parse_smethod_line(line, mp) < 0);
 
   reset_mp(mp);
 
   /* cowwect */
-  strcpy(line,"SMETHOD trebuchy 127.0.0.1:1999");
+  strlcpy(line,"SMETHOD trebuchy 127.0.0.1:1999",sizeof(line));
   test_assert(parse_smethod_line(line, mp) == 0);
 
   reset_mp(mp);
 
   /* unsupported version */
-  strcpy(line,"VERSION 666");
+  strlcpy(line,"VERSION 666",sizeof(line));
   test_assert(parse_version(line, mp) < 0);
 
   /* incomplete VERSION */
-  strcpy(line,"VERSION ");
+  strlcpy(line,"VERSION ",sizeof(line));
   test_assert(parse_version(line, mp) < 0);
 
   /* correct VERSION */
-  strcpy(line,"VERSION 1");
+  strlcpy(line,"VERSION 1",sizeof(line));
   test_assert(parse_version(line, mp) == 0);
 
  done:
@@ -99,32 +99,32 @@ test_pt_protocol(void)
 
   /* various wrong protocol runs: */
 
-  strcpy(line,"VERSION 1");
+  strlcpy(line,"VERSION 1",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
 
-  strcpy(line,"VERSION 1");
+  strlcpy(line,"VERSION 1",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_BROKEN);
 
   reset_mp(mp);
 
-  strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999");
+  strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_BROKEN);
 
   reset_mp(mp);
 
   /* correct protocol run: */
-  strcpy(line,"VERSION 1");
+  strlcpy(line,"VERSION 1",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
 
-  strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999");
+  strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
 
-  strcpy(line,"CMETHODS DONE");
+  strlcpy(line,"CMETHODS DONE",sizeof(line));
   handle_proxy_line(line, mp);
   test_assert(mp->conf_state == PT_PROTO_CONFIGURED);
 
index d4634244868a2fadeaae45a4243c05f2314d6b0a..53626bb00e499c724e6e7073b7914c49cadf86c3 100644 (file)
@@ -2874,7 +2874,7 @@ test_util_eat_whitespace(void *ptr)
   (void)ptr;
 
   /* Try one leading ws */
-  strcpy(str, "fuubaar");
+  strlcpy(str, "fuubaar", sizeof(str));
   for (i = 0; i < sizeof(ws); ++i) {
     str[0] = ws[i];
     test_eq_ptr(str + 1, eat_whitespace(str));
@@ -2889,14 +2889,14 @@ test_util_eat_whitespace(void *ptr)
   test_eq_ptr(str,     eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Empty string */
-  strcpy(str, "");
+  strlcpy(str, "", sizeof(str));
   test_eq_ptr(str, eat_whitespace(str));
   test_eq_ptr(str, eat_whitespace_eos(str, str));
   test_eq_ptr(str, eat_whitespace_no_nl(str));
   test_eq_ptr(str, eat_whitespace_eos_no_nl(str, str));
 
   /* Only ws */
-  strcpy(str, " \t\r\n");
+  strlcpy(str, " \t\r\n", sizeof(str));
   test_eq_ptr(str + strlen(str), eat_whitespace(str));
   test_eq_ptr(str + strlen(str), eat_whitespace_eos(str, str + strlen(str)));
   test_eq_ptr(str + strlen(str) - 1,
@@ -2904,7 +2904,7 @@ test_util_eat_whitespace(void *ptr)
   test_eq_ptr(str + strlen(str) - 1,
               eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
-  strcpy(str, " \t\r ");
+  strlcpy(str, " \t\r ", sizeof(str));
   test_eq_ptr(str + strlen(str), eat_whitespace(str));
   test_eq_ptr(str + strlen(str),
               eat_whitespace_eos(str, str + strlen(str)));
@@ -2913,7 +2913,7 @@ test_util_eat_whitespace(void *ptr)
               eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Multiple ws */
-  strcpy(str, "fuubaar");
+  strlcpy(str, "fuubaar", sizeof(str));
   for (i = 0; i < sizeof(ws); ++i)
     str[i] = ws[i];
   test_eq_ptr(str + sizeof(ws), eat_whitespace(str));
@@ -2923,28 +2923,28 @@ test_util_eat_whitespace(void *ptr)
               eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Eat comment */
-  strcpy(str, "# Comment \n No Comment");
+  strlcpy(str, "# Comment \n No Comment", sizeof(str));
   test_streq("No Comment", eat_whitespace(str));
   test_streq("No Comment", eat_whitespace_eos(str, str + strlen(str)));
   test_eq_ptr(str, eat_whitespace_no_nl(str));
   test_eq_ptr(str, eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Eat comment & ws mix */
-  strcpy(str, " # \t Comment \n\t\nNo Comment");
+  strlcpy(str, " # \t Comment \n\t\nNo Comment", sizeof(str));
   test_streq("No Comment", eat_whitespace(str));
   test_streq("No Comment", eat_whitespace_eos(str, str + strlen(str)));
   test_eq_ptr(str + 1, eat_whitespace_no_nl(str));
   test_eq_ptr(str + 1, eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Eat entire comment */
-  strcpy(str, "#Comment");
+  strlcpy(str, "#Comment", sizeof(str));
   test_eq_ptr(str + strlen(str), eat_whitespace(str));
   test_eq_ptr(str + strlen(str), eat_whitespace_eos(str, str + strlen(str)));
   test_eq_ptr(str, eat_whitespace_no_nl(str));
   test_eq_ptr(str, eat_whitespace_eos_no_nl(str, str + strlen(str)));
 
   /* Blank line, then comment */
-  strcpy(str, " \t\n # Comment");
+  strlcpy(str, " \t\n # Comment", sizeof(str));
   test_eq_ptr(str + strlen(str), eat_whitespace(str));
   test_eq_ptr(str + strlen(str), eat_whitespace_eos(str, str + strlen(str)));
   test_eq_ptr(str + 2, eat_whitespace_no_nl(str));