From a9a334a55a6a1ac59fac701095155b8a0a38622c Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Mon, 20 May 2024 16:25:42 +0300 Subject: [PATCH] safestringlib: unittests: do not crash on len > RSIZE_MAX_STR In test for strtolowercase_s() strtouppercase_s(), that were checking RSIZE_MAX_STR enforcement have operated on read-only memory causing bus error and after the RSIZE_MAX_STR enlargement 9999 < RSIZE_MAX_STR Use RSIZE_MAX_STR + 1 to make len > RSIZE_MAX_STR Signed-off-by: Tomas Winkler --- unittests/test_strtolowercase_s.c | 6 ++++-- unittests/test_strtouppercase_s.c | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/unittests/test_strtolowercase_s.c b/unittests/test_strtolowercase_s.c index 22f83e7..3c98e93 100644 --- a/unittests/test_strtolowercase_s.c +++ b/unittests/test_strtolowercase_s.c @@ -40,8 +40,10 @@ int test_strtolowercase_s() /*--------------------------------------------------*/ - len = 99999; - rc = strtolowercase_s("test", len); + len = RSIZE_MAX_STR + 1; + strcpy(str, "TEST"); + + rc = strtolowercase_s(str, len); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); diff --git a/unittests/test_strtouppercase_s.c b/unittests/test_strtouppercase_s.c index b7de5f1..d7e4268 100644 --- a/unittests/test_strtouppercase_s.c +++ b/unittests/test_strtouppercase_s.c @@ -53,11 +53,11 @@ int test_strtouppercase_s() /*--------------------------------------------------*/ -/* FIXME: known bug: this test causes a bus error if the string max size is - not restricted via RSIZE_MAX_STR */ - len = 99999; + len = RSIZE_MAX_STR + 1; + strcpy (str, "test"); + //printf("debug - 04\n"); - rc = strtouppercase_s("test", len); + rc = strtouppercase_s(str, len); if (rc != ESLEMAX) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc );