module-avb: add zero padding check function

This commit is contained in:
Nils Tonnaett 2026-05-13 11:53:43 -07:00 committed by Wim Taymans
parent b47c07b9cd
commit 14b1c4d3dd
2 changed files with 22 additions and 0 deletions

View file

@ -76,3 +76,23 @@ int validate_utf8(uint8_t *str, size_t len) {
return 0;
}
}
int check_zero_padding(uint8_t const *str, size_t len)
{
size_t str_len = strnlen((char *)str, len);
/* String doesn't need to be null-terminated. Return success if there is no null in str */
if (str_len == len)
{
return 0;
}
for (int i = str_len; i < len; ++i)
{
if (str[i] != 0x00)
{
return -1;
}
}
return 0;
}

View file

@ -6,7 +6,9 @@
#include <stddef.h>
#include <stdint.h>
#include <string.h>
int validate_utf8(uint8_t *str, size_t len);
int check_zero_padding(uint8_t *str, size_t len);
#endif /* AVB_STRINGS_H */