Skip to content

Commit

Permalink
safestringlib: unittests: do not crash on len > RSIZE_MAX_STR
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tomasbw committed May 20, 2024
1 parent 3eef337 commit a9a334a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions unittests/test_strtolowercase_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions unittests/test_strtouppercase_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit a9a334a

Please sign in to comment.