summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2018-08-23 15:42:02 +0100
committerKen Sharp <ken.sharp@artifex.com>2018-08-24 09:13:51 +0100
commit8e9ce5016db968b40e4ec255a3005f2786cce45f (patch)
treee43814b25a39243f54c7832d2d25d63b2ceab461
parent241d91112771a6104de10b3948c3f350d6690c1d (diff)
Bug 699665 "memory corruption in aesdecode"
The specimen file calls aesdecode without specifying the key to be used, though it does manage to do enough work with the PDF interpreter routines to get access to aesdecode (which isn't normally available). This causes us to read uninitialised memory, which can (and often does) lead to a segmentation fault. In this commit we set the key to NULL explicitly during intialisation and then check it before we read it. If its NULL we just return. It seems bizarre that we don't return error codes, we should probably look into that at some point, but this prevents the code trying to read uninitialised memory.
-rw-r--r--base/aes.c3
-rw-r--r--base/saes.c1
2 files changed, 4 insertions, 0 deletions
diff --git a/base/aes.c b/base/aes.c
index a6bce9398..e86f000d2 100644
--- a/base/aes.c
+++ b/base/aes.c
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx,
662 } 662 }
663#endif 663#endif
664 664
665 if (ctx == NULL || ctx->rk == NULL)
666 return;
667
665 RK = ctx->rk; 668 RK = ctx->rk;
666 669
667 GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++; 670 GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
diff --git a/base/saes.c b/base/saes.c
index 6db0e8b86..307ed74e8 100644
--- a/base/saes.c
+++ b/base/saes.c
@@ -120,6 +120,7 @@ s_aes_process(stream_state * ss, stream_cursor_read * pr,
120 gs_throw(gs_error_VMerror, "could not allocate aes context"); 120 gs_throw(gs_error_VMerror, "could not allocate aes context");
121 return ERRC; 121 return ERRC;
122 } 122 }
123 memset(state->ctx, 0x00, sizeof(aes_context));
123 if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) { 124 if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) {
124 gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)", 125 gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)",
125 state->keylength); 126 state->keylength);