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:
Ben Chan
2014-02-13 13:10:17 -08:00
committed by Aleksander Morgado
parent 0ce4244517
commit d278f381d2

View File

@@ -100,13 +100,13 @@ process_next_command (TestPortContext *ctx,
static const gchar *error_response = "\r\nERROR\r\n"; static const gchar *error_response = "\r\nERROR\r\n";
/* Find command end */ /* 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++; i++;
if (i == buffer->len) if (i == buffer->len)
/* no command */ /* no command */
return NULL; 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'; buffer->data[i++] = '\0';
/* Setup command and lookup response */ /* Setup command and lookup response */