From 304766ffa89eb5a0a09def996de4fc217955ab63 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 26 Apr 2024 18:30:11 +0100 Subject: [PATCH] Add early exit if zero length AEAD AD passed in. With multipart AEAD, if we attempt to add zero length additional data, then with the buffer sharing fixes this can now lead to undefined behaviour when using gcm. Fix this by returning early, as there is nothing to do if the input length is zero. Signed-off-by: Paul Elliott --- library/psa_crypto.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 969c695ac0..0a9011ad84 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5194,6 +5194,12 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation, goto exit; } + /* No input to add (zero length), nothing to do. */ + if (input_length == 0) { + status = PSA_SUCCESS; + goto exit; + } + if (operation->lengths_set) { if (operation->ad_remaining < input_length) { status = PSA_ERROR_INVALID_ARGUMENT;