language.c fix possible buffer overrun

ensure zero termination regardless of data read from lang file

Change-Id: I0da0e787ffb10c9268557812b061cc3c452fbd0a
This commit is contained in:
William Wilgus 2021-08-02 19:50:47 -04:00 committed by William Wilgus
parent 3b6c3d769f
commit 1fc4a17e1c

View file

@ -86,7 +86,7 @@ int lang_load(const char *filename, const unsigned char *builtin,
lang_init(builtin, dest, max_id); lang_init(builtin, dest, max_id);
lseek(fd, foffset, SEEK_SET); lseek(fd, foffset, SEEK_SET);
read(fd, buffer, lang_size); read(fd, buffer, lang_size);
buffer[max_lang_size - 1] = '\0'; /* ensure buffer is null terminated */
while(lang_size>3) { while(lang_size>3) {
id = ((buffer[0]<<8) | buffer[1]); /* get two-byte id */ id = ((buffer[0]<<8) | buffer[1]); /* get two-byte id */
buffer += 2; /* pass the id */ buffer += 2; /* pass the id */