From 1fc4a17e1c3d774c843bdfc4f4638df2a666870e Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 2 Aug 2021 19:50:47 -0400 Subject: [PATCH] language.c fix possible buffer overrun ensure zero termination regardless of data read from lang file Change-Id: I0da0e787ffb10c9268557812b061cc3c452fbd0a --- apps/language.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/language.c b/apps/language.c index 7fe1258dea..1ad1d5c829 100644 --- a/apps/language.c +++ b/apps/language.c @@ -86,7 +86,7 @@ int lang_load(const char *filename, const unsigned char *builtin, lang_init(builtin, dest, max_id); lseek(fd, foffset, SEEK_SET); read(fd, buffer, lang_size); - + buffer[max_lang_size - 1] = '\0'; /* ensure buffer is null terminated */ while(lang_size>3) { id = ((buffer[0]<<8) | buffer[1]); /* get two-byte id */ buffer += 2; /* pass the id */ @@ -100,7 +100,7 @@ int lang_load(const char *filename, const unsigned char *builtin, while(*buffer) { /* pass the string */ lang_size--; buffer++; - } + } lang_size-=3; /* the id and the terminating zero */ buffer++; /* pass the terminating zero-byte */ }