[v1,1/2] String: Add three more overflow tests cases to test-strnlen.c

Message ID 20210623235902.1614933-1-goldstein.w.n@gmail.com
State Committed
Commit bd3a2b3ed18fdeff0b370110c35850b51d025e8c
Headers
Series [v1,1/2] String: Add three more overflow tests cases to test-strnlen.c |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Noah Goldstein June 23, 2021, 11:59 p.m. UTC
  No bug. Just seem like relevant cases given that strnlen will
use s + maxlen in many implementations.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
---
 string/test-strnlen.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

H.J. Lu June 24, 2021, 12:41 a.m. UTC | #1
On Wed, Jun 23, 2021 at 4:59 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> No bug. Just seem like relevant cases given that strnlen will
> use s + maxlen in many implementations.
>
> Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
> ---
>  string/test-strnlen.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/string/test-strnlen.c b/string/test-strnlen.c
> index f53e09263f..bb5d9b5f04 100644
> --- a/string/test-strnlen.c
> +++ b/string/test-strnlen.c
> @@ -117,6 +117,10 @@ do_overflow_tests (void)
>            do_test (0, i, ~len + i, BIG_CHAR);
>            do_test (0, i, ~len - buf_addr - i, BIG_CHAR);
>            do_test (0, i, ~len - buf_addr + i, BIG_CHAR);
> +
> +          do_test (0, i, -buf_addr, BIG_CHAR);
> +          do_test (0, i, j - buf_addr, BIG_CHAR);
> +          do_test (0, i, -buf_addr - j, BIG_CHAR);
>          }
>      }
>  }
> --
> 2.25.1
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.
  

Patch

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index f53e09263f..bb5d9b5f04 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -117,6 +117,10 @@  do_overflow_tests (void)
           do_test (0, i, ~len + i, BIG_CHAR);
           do_test (0, i, ~len - buf_addr - i, BIG_CHAR);
           do_test (0, i, ~len - buf_addr + i, BIG_CHAR);
+
+          do_test (0, i, -buf_addr, BIG_CHAR);
+          do_test (0, i, j - buf_addr, BIG_CHAR);
+          do_test (0, i, -buf_addr - j, BIG_CHAR);
         }
     }
 }