aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2018-11-19 21:27:42 +0100
committerTimo Weingärtner <timo@tiwe.de>2018-11-19 21:31:37 +0100
commit87f2de93a6522bbcf17d1960e78641df8ecd85d3 (patch)
treef461cab1f3ac12af284a2c76e746f9f4d823b357
parentbb0c140c38ef26352ad5618ddb4aebb1e184c50d (diff)
downloadssh-agent-filter-87f2de93a6522bbcf17d1960e78641df8ecd85d3.tar.gz
base64_encode: fix two-byte out-of-bounds stack write
BASE64_ENCODE_LENGTH() calculates the encoded size without padding
-rw-r--r--ssh-agent-filter.C9
1 files changed, 3 insertions, 6 deletions
diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C
index 307be1f..b6d906b 100644
--- a/ssh-agent-filter.C
+++ b/ssh-agent-filter.C
@@ -116,12 +116,9 @@ string md5_hex (string const & s) {
}
string base64_encode (string const & s) {
- struct base64_encode_ctx ctx;
- base64_encode_init(&ctx);
- char b64[BASE64_ENCODE_LENGTH(s.size())];
- auto len = base64_encode_update(&ctx, b64, s.size(), reinterpret_cast<uint8_t const *>(s.data()));
- len += base64_encode_final(&ctx, b64 + len);
- return {b64, len};
+ char b64[BASE64_ENCODE_RAW_LENGTH(s.size())];
+ base64_encode_raw(b64, s.size(), reinterpret_cast<uint8_t const *>(s.data()));
+ return {b64, sizeof(b64)};
}
void cloexec (int fd) {