Page MenuHomeFreeBSD

D13682.id38075.diff
No OneTemporary

D13682.id38075.diff

Index: lib/libc/string/Makefile.inc
===================================================================
--- lib/libc/string/Makefile.inc
+++ lib/libc/string/Makefile.inc
@@ -50,6 +50,7 @@
ffs.3 flsll.3
MLINKS+=index.3 rindex.3
MLINKS+=memchr.3 memrchr.3
+MLINKS+=memset.3 memset_s.3
MLINKS+=strcasecmp.3 strncasecmp.3 \
strcasecmp.3 strcasecmp_l.3 \
strcasecmp.3 strncasecmp_l.3
Index: lib/libc/string/memset.3
===================================================================
--- lib/libc/string/memset.3
+++ lib/libc/string/memset.3
@@ -43,7 +43,9 @@
.Sh SYNOPSIS
.In string.h
.Ft void *
-.Fn memset "void *b" "int c" "size_t len"
+.Fn memset "void *dest" "int c" "size_t len"
+.Ft errno_t
+.Fn memset_s "void *dest" "rsize_t destsz" "int c" "rsize_t len"
.Sh DESCRIPTION
The
.Fn memset
@@ -55,13 +57,73 @@
(converted to an
.Vt "unsigned char" )
to the string
-.Fa b .
+.Fa dest .
+Undefined behaviour, resulting in storage overlay, will occur if
+.Fa len
+is greater than the the length of buffer
+.Fa dest .
+The behaviour is also undefined if the pointer
+.Fa dest
+is NULL.
+.Pp
+The
+.Fn memset_s
+function performs the same as
+.Fn memset
+except that an error is thrown and constraint handler is called if
+.Fa dest
+is a null pointer,
+.Sp
+.Fa destsz
+or
+.Fa len
+is greater than
+.Dv RSIZE_MAX ,
+or
+.Sp
+.Fa len
+is greater than
+.Fa destsz
+(buffer overflow would occur).
+Like
+.Xr 3 explicit_bzero ,
+.Fn memset_s
+is not removed through Dead Store Elimination (DSE) making it useful for
+clearing sensitve data.
+The
+.Fn memset
+function on the other hand may be optimized away if the object modified by
+the function is not accessed again.
+For this reason it is advised to use
+.Fn memset_s ,
+instead of
+.Fn memset ,
+to clear subsequently unreferenced memory.
+For instance, a buffer containing the password should be cleared with
+.Fn memset_s
+before
+.Xr 3 free .
+.Pp
+Undefined bahavour resulting in a possible storage overlay due to incorrect
+value of
+.Fa destsz .
+In other words,
+.Fa dest
+<
+.Fa len
+<=
+.Fa destsz
+can cause a buffer overrun.
.Sh RETURN VALUES
The
.Fn memset
function returns its first argument.
+The
+.Fn memset_s
+function returns zero on success, non-zero on error.
.Sh SEE ALSO
.Xr bzero 3 ,
+.Xr explicit_bzero 3 ,
.Xr swab 3 ,
.Xr wmemset 3
.Sh STANDARDS
@@ -70,3 +132,7 @@
function
conforms to
.St -isoC .
+.Fn memset_s
+conforms to:
+.St -isoC-2011
+K.3.7.4.1.

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 17, 1:56 PM (4 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25419251
Default Alt Text
D13682.id38075.diff (2 KB)

Event Timeline