diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-04-19 12:44:31 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-04-19 12:47:51 -0400 |
commit | 9c9e07963dddff6e11330e9dc8ad7a6d37da4aa4 (patch) | |
tree | 828aa0c372c47db725ad37b597d9c1fde345b57a /src/ext/tinytest.c | |
parent | 4d51dcda2fa75a3841e041ab7c3de325d73e2850 (diff) | |
download | tor-9c9e07963dddff6e11330e9dc8ad7a6d37da4aa4.tar.gz tor-9c9e07963dddff6e11330e9dc8ad7a6d37da4aa4.zip |
scan-build: truncate tinytest hexified outputs to 1024 bytes.
scan-build didn't like the unlimited version since we might need to
overflow size_t to hexify a string that took up half our address
space. (!)
Diffstat (limited to 'src/ext/tinytest.c')
-rw-r--r-- | src/ext/tinytest.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/ext/tinytest.c b/src/ext/tinytest.c index 3a8e331055..cc054ad340 100644 --- a/src/ext/tinytest.c +++ b/src/ext/tinytest.c @@ -478,16 +478,23 @@ tinytest_format_hex_(const void *val_, unsigned long len) const unsigned char *val = val_; char *result, *cp; size_t i; + int ellipses = 0; if (!val) return strdup("null"); - if (!(result = malloc(len*2+1))) + if (len > 1024) { + ellipses = 3; + len = 1024; + } + if (!(result = malloc(len*2+4))) return strdup("<allocation failure>"); cp = result; for (i=0;i<len;++i) { *cp++ = "0123456789ABCDEF"[val[i] >> 4]; *cp++ = "0123456789ABCDEF"[val[i] & 0x0f]; } + while (ellipses--) + *cp++ = '.'; *cp = 0; return result; } |