tests: fix array bound checks in process_next_command
This patch fixes the out-of-bounds array accesses in test-port-context.c, which is detected by AddressSanitizer, by checking the index against the array length before accessing the array.
This commit is contained in:

committed by
Aleksander Morgado

parent
0ce4244517
commit
d278f381d2
@@ -100,13 +100,13 @@ process_next_command (TestPortContext *ctx,
|
||||
static const gchar *error_response = "\r\nERROR\r\n";
|
||||
|
||||
/* Find command end */
|
||||
while (buffer->data[i] != '\r' && buffer->data[i] != '\n' && i < buffer->len)
|
||||
while (i < buffer->len && buffer->data[i] != '\r' && buffer->data[i] != '\n')
|
||||
i++;
|
||||
if (i == buffer->len)
|
||||
/* no command */
|
||||
return NULL;
|
||||
|
||||
while ((buffer->data[i] == '\r' || buffer->data[i] == '\n') && i < buffer->len)
|
||||
while (i < buffer->len && (buffer->data[i] == '\r' || buffer->data[i] == '\n'))
|
||||
buffer->data[i++] = '\0';
|
||||
|
||||
/* Setup command and lookup response */
|
||||
|
Reference in New Issue
Block a user