mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-09 23:18:05 +00:00
Fix uninitialized loop variable in GcmParser causing undefined behavior (#1163)
In GcmParser::parse(), the authentication check loop used an uninitialized loop counter: `for(uint8_t i; i < 16; i++)`. This is undefined behavior in C++ because `i` has an indeterminate value, potentially causing the authentication check to be skipped entirely or to read out-of-bounds memory. Fix: initialize `i` to 0 so the loop correctly iterates all 16 bytes of the authentication key. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ int8_t GCMParser::parse(uint8_t *d, DataParserContext &ctx, bool hastag) {
|
||||
footersize += authkeylen;
|
||||
memcpy(additional_authenticated_data + 1, authentication_key, 16);
|
||||
memcpy(authentication_tag, ptr + len - footersize - 5, authkeylen);
|
||||
for(uint8_t i; i < 16; i++) authenticate |= authentication_key[i] > 0;
|
||||
for(uint8_t i = 0; i < 16; i++) authenticate |= authentication_key[i] > 0;
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
|
||||
Reference in New Issue
Block a user