From 4c4a7758dd450d4a19ace0435a734c8ccfc1aa98 Mon Sep 17 00:00:00 2001 From: rgrimes Date: Tue, 22 Jan 2019 21:52:07 +0000 Subject: [PATCH] MFC: 325765 (imp) Add notes about overlapping copies. Add notes to each of these that specifically state that results are undefined if the strings overlap. In the case of memcpy, we document the overlapping behavior on FreeBSD (pre-existing). For str*, it is left unspecified, however, since the default (and x86) implementations do not handle overlapping strings properly. PR: 223653 Approved by: phk (mentor) git-svn-id: svn://svn.freebsd.org/base/stable/10@343326 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libc/string/memcpy.3 | 5 +++++ lib/libc/string/strcat.3 | 10 ++++++++++ lib/libc/string/strcpy.3 | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/libc/string/memcpy.3 b/lib/libc/string/memcpy.3 index 25a6c359f..febc0fa34 100644 --- a/lib/libc/string/memcpy.3 +++ b/lib/libc/string/memcpy.3 @@ -54,6 +54,11 @@ bytes from string .Fa src to string .Fa dst . +If +.Fa src +and +.Fa dst +overlap, the results are not defined. .Sh RETURN VALUES The .Fn memcpy diff --git a/lib/libc/string/strcat.3 b/lib/libc/string/strcat.3 index 802226980..a6d0fcef6 100644 --- a/lib/libc/string/strcat.3 +++ b/lib/libc/string/strcat.3 @@ -62,6 +62,11 @@ then add a terminating The string .Fa s must have sufficient space to hold the result. +If +.Fa s +and +.Fa append +overlap, the results are undefined. .Pp The .Fn strncat @@ -72,6 +77,11 @@ characters from .Fa append , and then adds a terminating .Ql \e0 . +If +.Fa s +and +.Fa append +overlap, the results are undefined. .Sh RETURN VALUES The .Fn strcat diff --git a/lib/libc/string/strcpy.3 b/lib/libc/string/strcpy.3 index 4d4a1ee7b..bc555411d 100644 --- a/lib/libc/string/strcpy.3 +++ b/lib/libc/string/strcpy.3 @@ -63,6 +63,11 @@ to (including the terminating .Ql \e0 character.) +If +.Fa src +and +.Fa dst +overlap, the results are undefined. .Pp The .Fn stpncpy @@ -89,6 +94,11 @@ Otherwise, is .Em not terminated. +If +.Fa src +and +.Fa dst +overlap, the results are undefined. .Sh RETURN VALUES The .Fn strcpy -- 2.42.0