Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# safestringlib

## v1.3.0:

- parse_format: fail on unrecognized modifier
- strcpyfldin_s: avoid read over slen
- strremovews_s: check lower bound
- strcspn_s: check smax first in read
- strcmpfld_s: do not fill indicator on equal string
- fix wchar bound checking
- avoid redefining RSIZE_MAX
- cmake: BUILD_OPT_DEFAULT type should be bool
- cmake: do not probe for C++
- cmake: update minimal version to 3.15
- unittests: do not crash on len > RSIZE_MAX_STR
- align str rsize with the mem rsize
- workflows: upgrade actions version
- workflows: set top level read permissions
- silence unused parameters warning in error handlers
- safeclib/strpbrk_s.c: check string boundaries
- add Cmake support for creating a Debian package
- remove makefile it does not work anymore
- requires cmake version 3.5 or higer
- workflows: add codeql testing
- add security policy file

## v1.2.0:
- unittests: add test counter to strisdigit_s and strismixed_s.c
- fix out of bounds check in stris_xxx functions
Expand Down
4 changes: 2 additions & 2 deletions include/safe_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ extern "C" {

/* Define safe_lib version number */
#define SAFEC_VERSION_MAJOR 1
#define SAFEC_VERSION_MINOR 2
#define SAFEC_VERSION_MINOR 3
#define SAFEC_VERSION_PATCH 0
#define SAFEC_VERSION_STRING "1.2.0"
#define SAFEC_VERSION_STRING "1.3.0"

#define SAFEC_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
#define SAFEC_VERSION \
Expand Down
8 changes: 5 additions & 3 deletions safeclib/snprintf_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

#define CHK_FORMAT(X,Y) (((X)==(Y))?1:0)


unsigned int
/*
* Partial parser for sanity checks
*/
static unsigned int
parse_format(const char *format, char pformatList[], unsigned int maxFormats)
{
unsigned int numFormats = 0;
Expand Down Expand Up @@ -167,7 +169,7 @@ parse_format(const char *format, char pformatList[], unsigned int maxFormats)
printf("failed to recognize format string [");
for (;start<index; start++) { printf("%c", format[start]); }
puts("]");
break;
return 0;
}
} else {
index++; // move past this character
Expand Down
2 changes: 1 addition & 1 deletion safeclib/strcmpfld_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ strcmpfld_s (const char *dest, rsize_t dmax,
while (dmax) {

if (*dest != *src) {
*indicator = *dest - *src;
break;
}

Expand All @@ -113,7 +114,6 @@ strcmpfld_s (const char *dest, rsize_t dmax,
dmax--;
}

*indicator = *dest - *src;
return (EOK);
}
EXPORT_SYMBOL(strcmpfld_s)
6 changes: 4 additions & 2 deletions safeclib/strcpyfldin_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ strcpyfldin_s (char *dest, rsize_t dmax, const char *src, rsize_t slen)
if (dest < src) {
overlap_bumper = src;

while (dmax > 0 && *src) {
while (dmax > 0 && slen && *src) {

if (dest == overlap_bumper) {
dmax = orig_dmax;
Expand All @@ -142,13 +142,14 @@ strcpyfldin_s (char *dest, rsize_t dmax, const char *src, rsize_t slen)
}

dmax--;
slen--;
*dest++ = *src++;
}

} else {
overlap_bumper = dest;

while (dmax > 0 && *src) {
while (dmax > 0 && slen && *src) {

if (src == overlap_bumper) {
dmax = orig_dmax;
Expand All @@ -164,6 +165,7 @@ strcpyfldin_s (char *dest, rsize_t dmax, const char *src, rsize_t slen)
}

dmax--;
slen--;
*dest++ = *src++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion safeclib/strcspn_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ strcspn_s (const char *dest, rsize_t dmax,
*/
smax = slen;
scan2 = src;
while (*scan2 && smax) {
while (smax && *scan2) {

if (*dest == *scan2) {
return RCNEGATE(EOK);
Expand Down
2 changes: 1 addition & 1 deletion safeclib/strremovews_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ strremovews_s (char *dest, rsize_t dmax)
* strip trailing whitespace
*/
dest = orig_end;
while ((*dest == ' ') || (*dest == '\t')) {
while ((dest >= orig_dest) && ((*dest == ' ') || (*dest == '\t'))) {
*dest = '\0';
dest--;
}
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wcpcpy_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ wcpcpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, errno_t *err)
return NULL;
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcpcpy_s: dmax exceeds max",
NULL, ESLEMAX);
*err = RCNEGATE(ESLEMAX);
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wcscat_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ wcscat_s(wchar_t* dest, rsize_t dmax, const wchar_t* src)
return RCNEGATE(ESZEROL);
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcscat_s: dmax exceeds max",
NULL, ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wcscpy_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ wcscpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src)
return RCNEGATE(ESZEROL);
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcscpy_s: dmax exceeds max",
NULL, ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand Down
4 changes: 2 additions & 2 deletions safeclib/wcsncat_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ wcsncat_s (wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize_t slen)
return RCNEGATE(ESNULLP);
}

if (slen*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (slen > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcsncat_s: slen exceeds max",
NULL, ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand All @@ -106,7 +106,7 @@ wcsncat_s (wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize_t slen)
return RCNEGATE(ESZEROL);
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcsncat_s: dmax exceeds max",
NULL, ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand Down
4 changes: 2 additions & 2 deletions safeclib/wcsncpy_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ wcsncpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, rsize_t slen)
return RCNEGATE(ESZEROL);
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcsncpy_s: dmax exceeds max",
NULL, ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand All @@ -121,7 +121,7 @@ wcsncpy_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, rsize_t slen)
return RCNEGATE(ESZEROL);
}

if (slen*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (slen > RSIZE_MAX_STR / sizeof(wchar_t)) {
handle_wc_error(orig_dest, orig_dmax, "wcsncpy_s: slen exceeds max",
ESLEMAX);
return RCNEGATE(ESLEMAX);
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wcsnlen_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ wcsnlen_s (const wchar_t *dest, rsize_t dmax)
return RCNEGATE(0);
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_STR) {
if (dmax > RSIZE_MAX_STR / sizeof(wchar_t)) {
invoke_safe_str_constraint_handler("wcsnlen_s: dmax exceeds max",
NULL, ESLEMAX);
return RCNEGATE(0);
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wmemmove_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ wmemmove_s(wchar_t* dest, rsize_t dmax, const wchar_t* src, size_t smax)
return (RCNEGATE(ESZEROL));
}

if (dmax*sizeof(wchar_t) > RSIZE_MAX_MEM) {
if (dmax > RSIZE_MAX_MEM / sizeof(wchar_t)) {
invoke_safe_mem_constraint_handler("wmemmove_s: dmax exceeds max",
NULL, ESLEMAX);
return (RCNEGATE(ESLEMAX));
Expand Down
2 changes: 1 addition & 1 deletion safeclib/wmemset_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ wmemset_s (wchar_t *dest, wchar_t value, rsize_t len)
return (RCNEGATE(ESZEROL));
}

if (len*sizeof(wchar_t) > RSIZE_MAX_MEM) {
if (len > RSIZE_MAX_MEM / sizeof(wchar_t)) {
invoke_safe_mem_constraint_handler("wmemset_s: len exceeds max",
NULL, ESLEMAX);
return (RCNEGATE(ESLEMAX));
Expand Down
Loading