Fix ZUC out-of-bounds read

This commit is contained in:
Zhi Guan
2026-06-14 15:36:02 +08:00
parent 5c67b5963d
commit f6f049256c
4 changed files with 13 additions and 7 deletions

View File

@@ -325,11 +325,11 @@ void zuc_encrypt(ZUC_STATE *state, const uint8_t *in, size_t inlen, uint8_t *out
}
LFSR[15] = V;
// xor with plaintext
Z ^= GETU32(in);
// output ciphertext
if (inlen >= 4) {
// xor with plaintext
Z ^= GETU32(in);
PUTU32(out, Z);
inlen -= 4;
in += 4;
@@ -338,6 +338,11 @@ void zuc_encrypt(ZUC_STATE *state, const uint8_t *in, size_t inlen, uint8_t *out
uint8_t word[4];
size_t i;
memcpy(word, in, inlen);
// xor with plaintext
Z ^= GETU32(word);
PUTU32(word, Z);
for (i = 0; i < inlen; i++) {
out[i] = word[i];