libkmipclient: Fix size underflow when padding bytes exceed remaining size

When decoding a value that is exactly at the boundary of the available size
(i.e., *size == value_len), and the value length is not a multiple of the
TTLV block length, then *size wraps to a huge value when the pad_len is
subtracted.

Assisted-by: IBM Bob:2.0.0
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Finn Callies <fcallies@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Ingo Franzki
2026-06-30 13:21:48 +02:00
committed by Jan Höppner
parent c7d0d3c1b9
commit 7d56dde24a

View File

@@ -166,8 +166,15 @@ int kmip_decode_ttlv(BIO *bio, size_t *size, struct kmip_node **node,
rc = -EIO;
goto out;
}
if (size != NULL)
if (size != NULL) {
if (*size < pad_len) {
rc = -EMSGSIZE;
goto out;
}
*size -= pad_len;
}
}
switch (n->type) {