Project

General

Profile

Bug #6168

strlcpy() does not return s1

Added by Marcel Telka about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Low
Category:
manpage - manual pages
Start date:
2015-08-28
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage

Description

In both string(3c) and string(9f) man pages there is this wording used:

   strcpy(), strncpy(), strlcpy()
       The strcpy() function copies string s2 to s1, including the terminating
       null character, stopping after the null character has been copied.  The
       strncpy() function copies exactly n bytes, truncating s2 or adding null
       characters to s1 if necessary. The result will not be null-terminated
       if the length of s2 is n or more. Each function returns s1.  If copying

Obviously, the strlcpy() does not return s1, so the following sentence:

Each function returns s1.

should be changed to:

Both strcpy() and strncpy() functions returns s1.

History

#1

Updated by Damian Wojslaw about 4 years ago

  • Assignee set to Damian Wojslaw
#2

Updated by Damian Wojslaw about 4 years ago

As per this implementation found in usr/src/common/util/string.c

size_t
strlcpy(char *dst, const char *src, size_t len)
{
    size_t slen = strlen(src);
    size_t copied;

    if (len == 0)
        return (slen);

    if (slen >= len)
        copied = len - 1;
    else
        copied = slen;
    bcopy(src, dst, copied);
    dst[copied] = '\0';
    return (slen);
}

and declaration in usr/src/stand/lib/sa/string.h

extern size_t        strlcpy(char *, const char *, size_t);

Marcel is right.
#3

Updated by Damian Wojslaw about 4 years ago

Patches inlined:

string9f

trochej@hipster:/code$ diff -u illumos-gate/usr/src/man/man9f/string.9f illumos-gate-6168/usr/src/man/man9f/string.9f 
--- illumos-gate/usr/src/man/man9f/string.9f    2015-08-19 15:47:17.058137967 +0200
+++ illumos-gate-6168/usr/src/man/man9f/string.9f       2015-09-08 09:40:33.574573018 +0200
@@ -176,9 +176,10 @@
 terminating null character, stopping after the null character has been copied.
 The \fBstrncpy()\fR function copies exactly \fIn\fR bytes, truncating \fIs2\fR
 or adding null characters to \fIs1\fR if necessary. The result will not be
-null-terminated if the length of \fIs2\fR is \fIn\fR or more. Each function
-returns \fIs1\fR.  If copying takes place between objects that overlap, the
-behavior of \fBstrcpy()\fR, \fBstrncpy()\fR, and \fBstrlcpy()\fR is undefined.
+null-terminated if the length of \fIs2\fR is \fIn\fR or more. Both \fBstrcpy()\fR 
+and \fBstrncpy()\fR functions return \fIs1\fR. If copying takes place between 
+objects that overlap, the behavior of \fBstrcpy()\fR, \fBstrncpy()\fR,
+and \fBstrlcpy()\fR is undefined.
 .sp
 .LP
 The \fBstrlcpy()\fR function copies  at most \fIdstsize\fR\(mi1 characters

string3c

trochej@hipster:/code$ diff -u illumos-gate/usr/src/man/man3c/string.3c illumos-gate-6168/usr/src/man/man3c/string.3c 
--- illumos-gate/usr/src/man/man3c/string.3c    2015-08-19 15:47:16.665050894 +0200
+++ illumos-gate-6168/usr/src/man/man3c/string.3c       2015-09-08 09:39:48.058169427 +0200
@@ -285,9 +285,10 @@
 terminating null character, stopping after the null character has been copied.
 The \fBstrncpy()\fR function copies exactly \fIn\fR bytes, truncating \fIs2\fR
 or adding null characters to \fIs1\fR if necessary. The result will not be
-null-terminated if the length of \fIs2\fR is \fIn\fR or more. Each function
-returns \fIs1\fR.  If copying takes place between objects that overlap, the
-behavior of \fBstrcpy()\fR, \fBstrncpy()\fR, and \fBstrlcpy()\fR is undefined.
+null-terminated if the length of \fIs2\fR is \fIn\fR or more. Both \fBstrcpy()\fR 
+and \fBstrncpy()\fR functions return \fIs1\fR. If copying takes place between 
+objects that overlap, the behavior of \fBstrcpy()\fR, \fBstrncpy()\fR, 
+and \fBstrlcpy()\fR is undefined. 
 .LP
 The \fBstrlcpy()\fR function copies  at most \fIdstsize\fR\(mi1 characters
 (\fIdstsize\fR being the  size of the  string buffer \fIdst\fR) from \fIsrc\fR

#5

Updated by Damian Wojslaw about 4 years ago

As a note, so I don't forget, link to thread on redundant manpage macros:

http://comments.gmane.org/gmane.os.illumos.devel/18143

#6

Updated by Electric Monk about 4 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit 6d532798b6559eb98b586fd17725d8093f3b9ade

commit  6d532798b6559eb98b586fd17725d8093f3b9ade
Author: Damian Wojslaw <damian@wojslaw.pl>
Date:   2015-09-15T19:20:19.000Z

    6168 strlcpy() does not return s1
    Reviewed by: Marcel Telka <marcel.telka@nexenta.com>
    Approved by: Robert Mustacchi <rm@joyent.com>

Also available in: Atom PDF