Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix odd length key buffer overrun in mz_crypt_hmac_init() #673

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions mz_crypt_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
key_blob_header_s *key_blob_s = NULL;
uint8_t *key_blob = NULL;
int32_t key_blob_size = 0;
int32_t pad_key_length = key_length;
int32_t result = 0;
int32_t err = MZ_OK;

Expand All @@ -565,9 +566,9 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
err = MZ_CRYPT_ERROR;
} else {
/* Zero-pad odd key lengths */
if (key_length % 2 == 1)
key_length += 1;
key_blob_size = sizeof(key_blob_header_s) + key_length;
if (pad_key_length % 2 == 1)
pad_key_length += 1;
key_blob_size = sizeof(key_blob_header_s) + pad_key_length;
key_blob = (uint8_t *)MZ_ALLOC(key_blob_size);
}

Expand All @@ -578,7 +579,7 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
key_blob_s->hdr.bVersion = CUR_BLOB_VERSION;
key_blob_s->hdr.aiKeyAlg = CALG_RC2;
key_blob_s->hdr.reserved = 0;
key_blob_s->key_length = key_length;
key_blob_s->key_length = pad_key_length;
nmoinvaz marked this conversation as resolved.
Show resolved Hide resolved

memcpy(key_blob + sizeof(key_blob_header_s), key, key_length);

Expand Down