summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-07 14:03:37 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-07 14:03:37 -0400
commit03e521670059c1b29f8b0068b8fe86700183b884 (patch)
tree81e308ba8919876ff481daaa03578df6acabf5df
parente9a315c2df95373dd9d9460ddbe15489df1ab44a (diff)
parentf1613b53c57af05250b71f31eda037bf82f1e725 (diff)
downloadtor-03e521670059c1b29f8b0068b8fe86700183b884.tar.gz
tor-03e521670059c1b29f8b0068b8fe86700183b884.zip
Merge branch 'maint-0.3.0' into release-0.3.0
-rw-r--r--changes/bug21894_0295
-rw-r--r--src/common/util_format.c7
2 files changed, 9 insertions, 3 deletions
diff --git a/changes/bug21894_029 b/changes/bug21894_029
new file mode 100644
index 0000000000..e3a84fa721
--- /dev/null
+++ b/changes/bug21894_029
@@ -0,0 +1,5 @@
+ o Minor bugfixes (crash prevention):
+ - Fix an (currently untriggerable, but potentially dangerous) crash
+ bug when base32-encoding inputs whose sizes are not a multiple of
+ 5. Fixes bug 21894; bugfix on 0.2.9.1-alpha.
+
diff --git a/src/common/util_format.c b/src/common/util_format.c
index 6e0a04586a..7e8ee1b868 100644
--- a/src/common/util_format.c
+++ b/src/common/util_format.c
@@ -51,9 +51,10 @@ base32_encode(char *dest, size_t destlen, const char *src, size_t srclen)
for (i=0,bit=0; bit < nbits; ++i, bit+=5) {
/* set v to the 16-bit value starting at src[bits/8], 0-padded. */
- v = ((uint8_t)src[bit/8]) << 8;
- if (bit+5<nbits)
- v += (uint8_t)src[(bit/8)+1];
+ size_t idx = bit / 8;
+ v = ((uint8_t)src[idx]) << 8;
+ if (idx+1 < srclen)
+ v += (uint8_t)src[idx+1];
/* set u to the 5-bit value at the bit'th bit of buf. */
u = (v >> (11-(bit%8))) & 0x1F;
dest[i] = BASE32_CHARS[u];