diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-21 23:13:29 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-21 23:13:29 +0000 |
commit | f99b91505bc823e07fae3c83b17210753fe8b3f8 (patch) | |
tree | 31f8ea40d5b4fb3948db4fe5c76199f7f994bfb5 | |
parent | 1cfcc4b351d426d22d1163a90bdc0525d897d801 (diff) | |
download | tor-f99b91505bc823e07fae3c83b17210753fe8b3f8.tar.gz tor-f99b91505bc823e07fae3c83b17210753fe8b3f8.zip |
Make write_escaped_data more bulletproof; backport candidate.
svn:r5106
-rw-r--r-- | src/or/control.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/or/control.c b/src/or/control.c index 36f0cffee2..9767d0e2e8 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -290,7 +290,7 @@ write_escaped_data(const char *data, size_t len, int translate_newlines, 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 @@ write_escaped_data(const char *data, size_t len, int translate_newlines, *outp++ = '.'; *outp++ = '\r'; *outp++ = '\n'; + *outp = '\0'; /* NUL-terminate just in case. */ + tor_assert((outp - *out) <= (sz_out)); return outp - *out; } |