[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make write_escaped_data more bulletproof; backport candidate.



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv26917/src/or

Modified Files:
	control.c 
Log Message:
Make write_escaped_data more bulletproof; backport candidate.

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -d -r1.130 -r1.131
--- control.c	14 Sep 2005 02:36:29 -0000	1.130
+++ control.c	21 Sep 2005 23:13:29 -0000	1.131
@@ -290,7 +290,7 @@
   int start_of_line;
   for (i=0; i<(int)len; ++i) {
     if (data[i]== '\n')
-      ++sz_out;
+      sz_out += 2; /* Maybe add a CR; maybe add a dot. */
   }
   *out = outp = tor_malloc(sz_out+1);
   end = data+len;
@@ -317,6 +317,8 @@
   *outp++ = '.';
   *outp++ = '\r';
   *outp++ = '\n';
+  *outp = '\0'; /* NUL-terminate just in case. */
+  tor_assert((outp - *out) <= (sz_out));
   return outp - *out;
 }