NetBSD Problem Report #59540
From www@netbsd.org Mon Jul 21 18:58:50 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 96CF91A9239
for <gnats-bugs@gnats.NetBSD.org>; Mon, 21 Jul 2025 18:58:50 +0000 (UTC)
Message-Id: <20250721185849.3511D1A923C@mollari.NetBSD.org>
Date: Mon, 21 Jul 2025 18:58:49 +0000 (UTC)
From: rwhitlock22@gmail.com
Reply-To: rwhitlock22@gmail.com
To: gnats-bugs@NetBSD.org
Subject: strlcpy(3) has an off-by-one in the manual page
X-Send-Pr-Version: www-1.0
>Number: 59540
>Category: lib
>Synopsis: strlcpy(3) has an off-by-one in the manual page
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: rillig
>State: closed
>Class: doc-bug
>Submitter-Id: net
>Arrival-Date: Mon Jul 21 19:00:00 +0000 2025
>Closed-Date: Wed Mar 04 19:38:58 +0000 2026
>Last-Modified: Wed Mar 04 19:38:58 +0000 2026
>Originator: Robert Whitlock
>Release: NetBSD current, 10.99.14, July 11, 2025
>Organization:
>Environment:
see above
>Description:
strlcpy(3) claims that strlcpy leaves bytes past dst[strlen(src) + 1] uninitialized, when it would be more precise to say that it leaves bytes past dst[strlen(src)] uninitialized. This can be easily seen by considering the case where src is the empty string "". Then strlen(src) == 0 and dst[strlen(src) + 1] == dst[1], which is one past the terminating NUL byte that is there when strlcpy has finished. The first byte past dst[1] is then the second byte past the NUL terminating byte.
The patch also includes a minor formatting fix.
>How-To-Repeat:
man strlcpy
>Fix:
Index: strlcpy.3
===================================================================
RCS file: /cvsroot/src/lib/libc/string/strlcpy.3,v
retrieving revision 1.25
diff -u -r1.25 strlcpy.3
--- strlcpy.3 2 Apr 2025 00:50:19 -0000 1.25
+++ strlcpy.3 21 Jul 2025 18:18:15 -0000
@@ -79,7 +79,7 @@
then the
.Fn strlcat
function returns
-.Fa size + Fn strlen src
+.Fa size Li + Fn strlen src
without writing anything to
.Fa dst .
.Pp
@@ -146,11 +146,11 @@
\(em
.Fn strlcpy
leaves bytes past
-.Fa dst Ns Li "[" Fn strlen src Li "+ 1" Ns Li "]"
+.Fa dst Ns Li "[" Fn strlen src Ns Li "]"
uninitialized, and
.Fn strlcat
leaves bytes past
-.Fa dst Ns Li "[" Fn strlen dst Li + Fn strlen src Li + 1 Ns Li "]"
+.Fa dst Ns Li "[" Fn strlen dst Li + Fn strlen src Ns Li "]"
uninitialized.
This can lead to security vulnerabilities such as leaking secrets from
uninitialized stack or heap buffers.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: lib-bug-people->rillig
Responsible-Changed-By: rillig@NetBSD.org
Responsible-Changed-When: Sun, 04 Jan 2026 14:33:33 +0000
Responsible-Changed-Why:
I'll handle it.
State-Changed-From-To: open->feedback
State-Changed-By: rillig@NetBSD.org
State-Changed-When: Sun, 04 Jan 2026 14:33:33 +0000
State-Changed-Why:
What about "dst + strlen(src) + 1" instead of the brackets notation?
That would keep the "+ 1" to emphasize the terminating null byte.
State-Changed-From-To: feedback->analyzed
State-Changed-By: rillig@NetBSD.org
State-Changed-When: Sun, 04 Jan 2026 15:37:07 +0000
State-Changed-Why:
State "feedback" is only for finished work.
From: "Roland Illig" <rillig@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59540 CVS commit: src/lib/libc/string
Date: Sun, 4 Jan 2026 17:01:30 +0000
Module Name: src
Committed By: rillig
Date: Sun Jan 4 17:01:30 UTC 2026
Modified Files:
src/lib/libc/string: strlcpy.3
Log Message:
strlcpy.3: fix off-by-one error (since 2023-08-11)
Patch provided by Robert Whitlock in PR lib/59540.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/string/strlcpy.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Roland Illig" <rillig@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59540 CVS commit: src/lib/libc/string
Date: Sun, 4 Jan 2026 17:16:39 +0000
Module Name: src
Committed By: rillig
Date: Sun Jan 4 17:16:39 UTC 2026
Modified Files:
src/lib/libc/string: strlcpy.3
Log Message:
strlcpy.3: update date for the recent change
Also needs to go to pull-ups for PR lib/59540.
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/string/strlcpy.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59540 CVS commit: [netbsd-11] src/lib/libc/string
Date: Wed, 4 Mar 2026 19:18:11 +0000
Module Name: src
Committed By: martin
Date: Wed Mar 4 19:18:11 UTC 2026
Modified Files:
src/lib/libc/string [netbsd-11]: strlcpy.3
Log Message:
Pull up following revision(s) (requested by rillig in ticket #190):
lib/libc/string/strlcpy.3: revision 1.26
lib/libc/string/strlcpy.3: revision 1.27
strlcpy.3: fix off-by-one error (since 2023-08-11)
Patch provided by Robert Whitlock in PR lib/59540.
strlcpy.3: update date for the recent change
Also needs to go to pull-ups for PR lib/59540.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.25.2.1 src/lib/libc/string/strlcpy.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: analyzed->closed
State-Changed-By: rillig@NetBSD.org
State-Changed-When: Wed, 04 Mar 2026 19:38:58 +0000
State-Changed-Why:
Done and pulled up to the netbsd-11 branch.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.