diff options
author | Ben Chan <benchan@chromium.org> | 2014-02-13 13:10:17 -0800 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-02-14 09:03:13 +0100 |
commit | d278f381d28f6a4ebc82f4f7ea838961ebb466a3 (patch) | |
tree | ff9f1cb55d054c598dd268c92edcad23fde5b8f4 /plugins/tests | |
parent | 0ce424451789a5ffacde7ff3cce038c2fbda97eb (diff) |
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.
Diffstat (limited to 'plugins/tests')
-rw-r--r-- | plugins/tests/test-port-context.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/plugins/tests/test-port-context.c b/plugins/tests/test-port-context.c index aad359e8..cbf202f0 100644 --- a/plugins/tests/test-port-context.c +++ b/plugins/tests/test-port-context.c @@ -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 */ |