Skip to content

Commit 5e032ec

Browse files
committed
safestringlib: Fix documentation to match implementation
Although the documentation describes destination buffers being filled with 0, that is only done when SAFECLIB_STR_NULL_SLACK is defined. Make the source documentation conditional on the same variable. Documentation outside the source is perpetually at risk of being different than how any particular library is built. A such, most documentation should assume that the clearing is not done, as that is the least risk assumption. Signed-off-by: Mark Rustad <[email protected]>
1 parent 3422505 commit 5e032ec

File tree

9 files changed

+69
-0
lines changed

9 files changed

+69
-0
lines changed

safeclib/stpcpy_s.c

+9
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@
4646
* DESCRIPTION
4747
* The stpcpy_s function copies the string pointed to by src
4848
* (including the terminating null character) into the array
49+
#ifdef SAFECLIB_STR_NULL_SLACK
4950
* pointed to by dest. All elements following the terminating
5051
* null character (if any) written by stpcpy_s in the array
5152
* of dmax characters pointed to by dest are nulled when
5253
* strcpy_s returns. The function returns a pointer to the
54+
#else
55+
* pointed to by dest. The function returns a pointer to the
56+
#endif // SAFECLIB_STR_NULL_SLACK
5357
* end of the string in dest - that is to the null terminator
5458
* of dest - upon return. If an error occurs, NULL is returned
5559
* and err is set to the error encountered.
@@ -88,7 +92,12 @@
8892
* Copying shall not take place between objects that overlap.
8993
* If there is a runtime-constraint violation, then if dest
9094
* is not a null pointer and destmax is greater than zero and
95+
#ifdef SAFECLIB_STR_NULL_SLACK
9196
* not greater than RSIZE_MAX_STR, then stpcpy_s nulls dest.
97+
#else
98+
* not greater than RSIZE_MAX_STR, then stpcpy_s stores a 0
99+
* terminator in dest.
100+
#endif // SAFECLIB_STR_NULL_SLACK
92101
*
93102
* RETURN VALUE
94103
* a char pointer to the terminating null at the end of dest

safeclib/stpncpy_s.c

+7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
* The stpncpy_s function copies at most smax characters from the string
4848
* pointed to by src, including the terminating null byte ('\0'), to the
4949
* array pointed to by dest. Exactly smax characters are written at dest.
50+
#ifdef SAFECLIB_STR_NULL_SLACK
5051
* If the length strlen_s(src) is smaller than smax, the remaining smax
5152
* characters in the array pointed to by dest are filled with null bytes.
53+
#endif // SAFECLIB_STR_NULL_SLACK
5254
* If the length strlen_s(src) is greater than or equal to smax, the string
5355
* pointed to by dest will contain smax characters from src plus a null
5456
* characters (dest will be null-terminated).
@@ -97,8 +99,13 @@
9799
* If src and dest overlap, copying shall be stopped; destruction of src may have occurred.
98100
* If there is a runtime-constraint violation, then:
99101
* if dest is not a null pointer and dmax is greater than zero and
102+
#ifdef SAFECLIB_STR_NULL_SLACK
100103
* not greater than RSIZE_MAX_STR, then stpncpy_s shall fill dest with nulls,
101104
* if library was compiled with SAFECLIB_STR_NULL_SLACK.
105+
#else
106+
* not greater than RSIZE_MAX_STR, then stpncpy_s shall write a terminator
107+
* to the dest buffer.
108+
#endif // SAFECLIB_STR_NULL_SLACK
102109
*
103110
* RETURN VALUE
104111
* a char pointer to the terminating null at the end of dest

safeclib/strcat_s.c

+7
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
* INPUT PARAMETERS
6363
* dest pointer to string that will be extended by src
6464
* if dmax allows. The string is null terminated.
65+
#ifdef SAFECLIB_STR_NULL_SLACK
6566
* If the resulting concatenated string is less
6667
* than dmax, the remaining slack space is nulled.
68+
#endif // SAFECLIB_STR_NULL_SLACK
6769
*
6870
* dmax restricted maximum length of the resulting dest,
6971
* including the null
@@ -82,7 +84,12 @@
8284
* Copying shall not takeplace between objects that overlap
8385
* If there is a runtime-constraint violation, then if dest is
8486
* not a null pointer and dmax is greater than zero and not
87+
#ifdef SAFECLIB_STR_NULL_SLACK
8588
* greater than RSIZE_MAX_STR, then strcat_s nulls dest.
89+
#else
90+
* greater than RSIZE_MAX_STR, then strcat_s writes a terminator
91+
* to dest.
92+
#endif // SAFECLIB_STR_NULL_SLACK
8693
*
8794
* RETURN VALUE
8895
* EOK successful operation, all the characters from src

safeclib/strcpy_s.c

+9
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@
4646
* DESCRIPTION
4747
* The strcpy_s function copies the string pointed to by src
4848
* (including the terminating null character) into the array
49+
#ifdef SAFECLIB_STR_NULL_SLACK
4950
* pointed to by dest. All elements following the terminating
5051
* null character (if any) written by strcpy_s in the array
5152
* of dmax characters pointed to by dest are nulled when
5253
* strcpy_s returns.
54+
#else
55+
* pointed to by dest.
56+
#endif // SAFECLIB_STR_NULL_SLACK
5357
*
5458
* SPECIFIED IN
5559
* ISO/IEC TR 24731, Programming languages, environments
@@ -75,7 +79,12 @@
7579
* Copying shall not take place between objects that overlap.
7680
* If there is a runtime-constraint violation, then if dest
7781
* is not a null pointer and destmax is greater than zero and
82+
#ifdef SAFECLIB_STR_NULL_SLACK
7883
* not greater than RSIZE_MAX_STR, then strcpy_s nulls dest.
84+
#else
85+
* not greater than RSIZE_MAX_STR, then strcpy_s writes a
86+
* terminator to dest.
87+
#endif // SAFECLIB_STR_NULL_SLACK
7988
*
8089
* RETURN VALUE
8190
* EOK successful operation, the characters in src were

safeclib/strncpy_s.c

+6
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
* (characters that follow a null character are not copied) from the
4949
* array pointed to by src to the array pointed to by dest. If no null
5050
* character was copied from src, then dest[n] is set to a null character.
51+
#ifdef SAFECLIB_STR_NULL_SLACK
5152
*
5253
* All elements following the terminating null character (if any)
5354
* written by strncpy_s in the array of dmax characters pointed to
5455
* by dest take on the null value when strncpy_s returns.
56+
#endif // SAFECLIB_STR_NULL_SLACK
5557
*
5658
* Specicified in:
5759
* ISO/IEC TR 24731-1, Programming languages, environments
@@ -82,7 +84,11 @@
8284
* Copying shall not take place between objects that overlap.
8385
* If there is a runtime-constraint violation, then if dest
8486
* is not a null pointer and dmax greater than RSIZE_MAX_STR,
87+
#ifdef SAFECLIB_STR_NULL_SLACK
8588
* then strncpy_s nulls dest.
89+
#else
90+
* the strncpy_s writes a terminator to dest.
91+
#endif // SAFECLIB_STR_NULL_SLACK
8692
*
8793
* RETURN VALUE
8894
* EOK successful operation, the characters in src were copied

safeclib/wcpcpy_s.c

+9
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@
4747
* The wcpcpy_s function copies the wide character string pointed
4848
* to by src (including the terminating null character) into the
4949
* array pointed to by dest, and returns a pointer to the end of
50+
#ifdef SAFECLIB_STR_NULL_SLACK
5051
* the wide character string. All elements following the terminating
5152
* null character (if any) written by wcpcpy_s in the array of
5253
* dmax characters pointed to by dest are nulled when
5354
* wcpcpy_s returns.
55+
#else
56+
* the wide character string.
57+
#endif // SAFECLIB_STR_NULL_SLACK
5458
*
5559
* SPECIFIED IN
5660
* ISO/IEC TR 24731, Programming languages, environments
@@ -86,7 +90,12 @@
8690
* Copying shall not take place between objects that overlap.
8791
* If there is a runtime-constraint violation, then if dest
8892
* is not a null pointer and destmax is greater than zero and
93+
#ifdef SAFECLIB_STR_NULL_SLACK
8994
* not greater than RSIZE_MAX_STR, then strcpy_s nulls dest.
95+
#else
96+
* not greater than RSIZE_MAX_STR, then strcpy_s stores a
97+
* terminator at dest.
98+
#endif // SAFECLIB_STR_NULL_SLACK
9099
*
91100
* RETURN VALUE
92101
* a wchar_t pointer to the terminating null at the end of dest

safeclib/wcscat_s.c

+7
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
* to by src (including the terminating null character) to the
4949
* end of the string pointed to by dest. The initial wide character
5050
* from src overwrites the null character at the end of dest.
51+
#ifdef SAFECLIB_STR_NULL_SLACK
5152
*
5253
* All elements following the terminating null character (if
5354
* any) written by strcat_s in the array of dmax characters
5455
* pointed to by dest take unspecified values when strcat_s
5556
* returns.
57+
#endif // SAFECLIB_STR_NULL_SLACK
5658
*
5759
* SPECIFIED IN
5860
* ISO/IEC TR 24731, Programming languages, environments
@@ -82,7 +84,12 @@
8284
* Copying shall not takeplace between objects that overlap
8385
* If there is a runtime-constraint violation, then if dest is
8486
* not a null pointer and dmax is greater than zero and not
87+
#ifdef SAFECLIB_STR_NULL_SLACK
8588
* greater than RSIZE_MAX_STR, then strcat_s nulls dest.
89+
#else
90+
* greater than RSIZE_MAX_STR, then strcat_s stores a
91+
* terminator at dest.
92+
#endif // SAFECLIB_STR_NULL_SLACK
8693
*
8794
* RETURN VALUE
8895
* EOK successful operation, all the characters from src

safeclib/wcscpy_s.c

+9
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@
4646
* DESCRIPTION
4747
* The wcscpy_s function copies the wide character string pointed
4848
* to by src (including the terminating null character) into the
49+
#ifdef SAFECLIB_STR_NULL_SLACK
4950
* array pointed to by dest. All elements following the terminating
5051
* null character (if any) written by strcpy_s in the array of
5152
* dmax characters pointed to by dest are nulled when
5253
* wcscpy_s returns.
54+
#else
55+
* array pointed to by dest.
56+
#endif // SAFECLIB_STR_NULL_SLACK
5357
*
5458
* SPECIFIED IN
5559
* ISO/IEC TR 24731, Programming languages, environments
@@ -75,7 +79,12 @@
7579
* Copying shall not take place between objects that overlap.
7680
* If there is a runtime-constraint violation, then if dest
7781
* is not a null pointer and destmax is greater than zero and
82+
#ifdef SAFECLIB_STR_NULL_SLACK
7883
* not greater than RSIZE_MAX_STR, then strcpy_s nulls dest.
84+
#else
85+
* not greater than RSIZE_MAX_STR, then strcpy_s stores a
86+
* terminator at dest.
87+
#endif // SAFECLIB_STR_NULL_SLACK
7988
*
8089
* RETURN VALUE
8190
* EOK successful operation, the characters in src were

safeclib/wcsncpy_s.c

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* (characters that follow a null character are not copied) from the
4949
* array pointed to by src to the array pointed to by dest. If no null
5050
* character was copied from src, then dest[slen] is set to a null character.
51+
#ifdef SAFECLIB_STR_NULL_SLACK
5152
*
5253
* All elements following the terminating null character (if any)
5354
* written by wcsncpy_s in the array of dmax characters pointed to
@@ -60,6 +61,7 @@
6061
* array is used multiple times to string manipulation routines in this
6162
* library. If this extra security is not required, ensure that the
6263
* library is compiled without #DEFINE SAFECLIB_STR_NULL_SLACK.
64+
#endif // SAFECLIB_STR_NULL_SLACK
6365
*
6466
* Specicified in:
6567
* ISO/IEC TR 24731-1, Programming languages, environments
@@ -90,7 +92,11 @@
9092
* Copying shall not take place between objects that overlap.
9193
* If there is a runtime-constraint violation, then if dest
9294
* is not a null pointer and dmax greater than RSIZE_MAX_STR,
95+
#ifdef SAFECLIB_STR_NULL_SLACK
9396
* then strncpy_s nulls dest.
97+
#else
98+
* then strncpy_s stores a terminator at dest.
99+
#endif // SAFECLIB_STR_NULL_SLACK
94100
*
95101
* RETURN VALUE
96102
* EOK successful operation, the characters in src were copied

0 commit comments

Comments
 (0)