From 460bbf886ec7118475714d395033bd90d23d328f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 30 Oct 2018 10:29:39 +0000 Subject: [PATCH] symm/cbc-def.h: Fix discarding output for short inputs. You got a segfault if the input was smaller than the block size and the destination pointer was null. We need a temporary place for shuffling the buffer around anyway, so it seems like the best approach is just to make a (necessarily small) dummy destination. --- symm/cbc-def.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/symm/cbc-def.h b/symm/cbc-def.h index 59c76f8a..480f5796 100644 --- a/symm/cbc-def.h +++ b/symm/cbc-def.h @@ -155,7 +155,7 @@ void pre##_cbcencrypt(pre##_cbcctx *ctx, \ { \ const octet *s = src; \ octet *d = dest; \ - octet b[PRE##_BLKSZ]; \ + octet b[PRE##_BLKSZ], bb[PRE##_BLKSZ]; \ octet y; \ unsigned i; \ \ @@ -173,7 +173,8 @@ void pre##_cbcencrypt(pre##_cbcctx *ctx, \ if (sz < PRE##_BLKSZ) { \ pre##_eblk(&ctx->ctx, ctx->a, ctx->a); \ BLKC_STORE(PRE, b, ctx->a); \ - if (d) { for (i = 0; i < sz; i++) d[i] = b[i] ^ (s ? s[i] : 0); } \ + if (!d) d = bb; \ + for (i = 0; i < sz; i++) d[i] = b[i] ^ (s ? s[i] : 0); \ memmove(b, b + sz, PRE##_BLKSZ - sz); \ memcpy(b + PRE##_BLKSZ - sz, d, sz); \ BLKC_LOAD(PRE, ctx->a, b); \ -- 2.11.0