diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-12-14 13:11:58 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-14 13:51:51 -0500 |
commit | 6dc90d290daa29b4ff2c7692be3a2ed64f25dfc1 (patch) | |
tree | 55b9eef602365ace7da004551dd7f44c4fd79c08 /src/feature/dirparse | |
parent | 3c35c0d441cc25f750524056113970a376d8432c (diff) | |
download | tor-6dc90d290daa29b4ff2c7692be3a2ed64f25dfc1.tar.gz tor-6dc90d290daa29b4ff2c7692be3a2ed64f25dfc1.zip |
Use 25% less RAM for base64-encoded directory objects
We were allocating N bytes to decode an N-byte base64 encoding,
when 3N/4 would have been enough.
Diffstat (limited to 'src/feature/dirparse')
-rw-r--r-- | src/feature/dirparse/parsecommon.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/feature/dirparse/parsecommon.c b/src/feature/dirparse/parsecommon.c index e00af0eea2..91b775533b 100644 --- a/src/feature/dirparse/parsecommon.c +++ b/src/feature/dirparse/parsecommon.c @@ -393,8 +393,9 @@ get_next_token(memarea_t *area, RET_ERR("Couldn't parse private key."); } else { /* If it's something else, try to base64-decode it */ int r; - tok->object_body = ALLOC(next-*s); /* really, this is too much RAM. */ - r = base64_decode(tok->object_body, next-*s, *s, next-*s); + size_t maxsize = base64_decode_maxsize(next-*s); + tok->object_body = ALLOC(maxsize); + r = base64_decode(tok->object_body, maxsize, *s, next-*s); if (r<0) RET_ERR("Malformed object: bad base64-encoded data"); tok->object_size = r; |