[PATCH] tests: fix array bound checks in process_next_command

Ben Chan benchan at chromium.org
Thu Feb 13 22:10:17 CET 2014


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.
---
 plugins/tests/test-port-context.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/tests/test-port-context.c b/plugins/tests/test-port-context.c
index aad359e..cbf202f 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 */
-- 
1.9.0.rc1.175.g0b1dcb5



More information about the ModemManager-devel mailing list