[PATCH] tests: fix array bound checks in process_next_command

Aleksander Morgado aleksander at aleksander.es
Fri Feb 14 09:06:40 CET 2014


On 13/02/14 22:10, Ben Chan wrote:
> 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.
> ---

Pushed, thanks.

>  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 */
> 


-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list