]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix off-by-one error when allocating memory in test_util_split_lines()
authorSteven Murdoch <Steven.Murdoch@cl.cam.ac.uk>
Wed, 31 Aug 2011 22:40:29 +0000 (23:40 +0100)
committerSteven Murdoch <Steven.Murdoch@cl.cam.ac.uk>
Wed, 31 Aug 2011 22:40:29 +0000 (23:40 +0100)
Triggered "failed OVER picket-fence magic-number check (err 27)" when
memory debugging using dmalloc is enabled (at 'low' or higher).

src/test/test_util.c

index 3b5d85f376d55170fbb24210a45b27a6fb818194..b903cbfb9caa17b0e2719d1bfc4ca5d601cb87b1 100644 (file)
@@ -1637,7 +1637,8 @@ test_util_split_lines(void *ptr)
 
   for (i=0; tests[i].orig_line; i++) {
     sl = smartlist_create();
-    orig_line = tor_malloc(tests[i].orig_length);
+    /* Allocate space for string and trailing NULL */
+    orig_line = tor_malloc(tests[i].orig_length + 1);
     memcpy(orig_line, tests[i].orig_line, tests[i].orig_length + 1);
     tor_split_lines(sl, orig_line, tests[i].orig_length);