fix: Fix boundary check error in libx52util

Prior to this change, if the input string terminates exactly when `len`
characters have been output, the libx52util_convert_utf8_string function
returns an error of `-E2BIG`, even though the buffer is sufficiently
large. Because the output buffer is not expected to be NUL terminated,
this additional character can be safely placed in the output buffer
without overrun.

This change checks for a non-NUL character when the index matches or
exceeds the output buffer length, and only then will it return -E2BIG.
pull/58/head
nirenjan 2026-03-08 20:30:03 -07:00
parent 762a3468b2
commit 2378ba7dc4
1 changed files with 1 additions and 1 deletions

View File

@ -48,7 +48,7 @@ int libx52util_convert_utf8_string(const uint8_t *input,
if (entry->type == TYPE_ENTRY) {
output[index] = entry->value;
index++;
if (index >= *len) {
if (index >= *len && *input) {
retval = -E2BIG;
break;
}