diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-02 13:29:45 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-02 13:29:45 -0400 |
commit | 9b850f9200c2d2eac4053cfaa74873bbbe4f0b95 (patch) | |
tree | 7d101df7a86d5d6ff8ffe059d084a14a55a2e22d | |
parent | 07a16b33724c90c74a96e42f89ccd1ccdcccf2a7 (diff) | |
download | tor-9b850f9200c2d2eac4053cfaa74873bbbe4f0b95.tar.gz tor-9b850f9200c2d2eac4053cfaa74873bbbe4f0b95.zip |
Add more assertions to esc_for_log to please the clangalyzer.
-rw-r--r-- | src/common/util.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index a7a7fcbea3..75dd6ed7f6 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1208,9 +1208,14 @@ esc_for_log(const char *s) } } + tor_assert(len <= SSIZE_MAX); + result = outp = tor_malloc(len); *outp++ = '\"'; for (cp = s; *cp; ++cp) { + /* This assertion should always succeed, since we will write at least + * one char here, and two chars for closing quote and nul later */ + tor_assert((outp-result) < (ssize_t)len-2); switch (*cp) { case '\\': case '\"': @@ -1234,6 +1239,7 @@ esc_for_log(const char *s) if (TOR_ISPRINT(*cp) && ((uint8_t)*cp)<127) { *outp++ = *cp; } else { + tor_assert((outp-result) < (ssize_t)len-4); tor_snprintf(outp, 5, "\\%03o", (int)(uint8_t) *cp); outp += 4; } @@ -1241,6 +1247,7 @@ esc_for_log(const char *s) } } + tor_assert((outp-result) <= (ssize_t)len-2); *outp++ = '\"'; *outp++ = 0; |