Skip to content

Commit 965fc8e

Browse files
Old-DingRbb666
authored andcommitted
bsp: nxp: Bound VGLite buffer reader access
Check the buffer limits before reading ptr[i] in bufferred_fgets(). Also guard CR/LF skipping against the available input bytes so reading a full buffer does not inspect one byte past the source. Generated-by: OpenAI Codex Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
1 parent 221502a commit 965fc8e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

bsp/nxp/imx/imxrt/libraries/drivers/vglite/font/buf_reader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ char *bufferred_fgets(char* buff, int len, bufferred_reader_t *fd)
190190
return NULL;
191191

192192
ptr = fd->data_buf + fd->index;
193-
for(i=0; ptr[i] != '\0' && i < len; i++)
193+
for(i=0; i < len && ptr[i] != '\0'; i++)
194194
{
195195
if ( ptr[i] == '\n' )
196196
break;
@@ -201,9 +201,9 @@ char *bufferred_fgets(char* buff, int len, bufferred_reader_t *fd)
201201
buff[i] = '\0';
202202
j = i;
203203
/* skip trailing newline from file buffer */
204-
if ( ptr[i] == '\r' )
204+
if ( i < valid_bytes && ptr[i] == '\r' )
205205
i++;
206-
if ( ptr[i] == '\n' )
206+
if ( i < valid_bytes && ptr[i] == '\n' )
207207
i++;
208208
fd->index += i;
209209

0 commit comments

Comments
 (0)