NetBSD Problem Report #60744

From www@netbsd.org  Fri Sep 18 21:53:14 2026
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 "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 13DF31A923B
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 18 Sep 2026 21:53:14 +0000 (UTC)
Message-Id: <20260918215312.C55AA1A923C@mollari.NetBSD.org>
Date: Fri, 18 Sep 2026 21:53:12 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: memchr(3) is busticated
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60744
>Category:       lib
>Synopsis:       memchr(3) is busticated
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          pending-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 18 21:55:00 +0000 2026
>Closed-Date:    
>Last-Modified:  Sat Oct 24 11:35:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11, 10, ...
>Organization:
The Memchr Foundation, Inc.
>Environment:
>Description:

	We have a very clever hand-written assembly memchr function --
	it gives answers very quickly, but sometimes the answers are
	wrong.  Clever, isn't it?

	For example, if s is a pointer to a NUL byte, memchr(s, 0, -1)
	should return s, but it does not -- it returns a null pointer:

$ cat memchr0.c
#include <string.h>

int
main(void)
{
	const char s[] = "";
	return (memchr(s, 0, (size_t)-1) == s ? 0 : 1);
}
$ cc -o memchr0 -fno-builtin -O2 memchr0.c
$ ./memchr0
$ echo $?
1

>How-To-Repeat:

	as above

>Fix:

	1. Add a test.
	2. Fix the size=-1 case and whatever else is broken on amd64.
	3. Audit all the other memchr.S files too.

>Release-Note:

>Audit-Trail:
From: "Nia Alarie" <nia@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: src/tests/lib/libc/string
Date: Fri, 18 Sep 2026 22:32:24 +0000

 Module Name:	src
 Committed By:	nia
 Date:		Fri Sep 18 22:32:24 UTC 2026

 Modified Files:
 	src/tests/lib/libc/string: Makefile t_memchr.c

 Log Message:
 PR lib/60744 demonstrate memchr(3) is busticated with a test


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/string/Makefile
 cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/string/t_memchr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Nia Alarie" <nia@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: src/tests/lib/libc/string
Date: Sat, 19 Sep 2026 09:40:56 +0000

 Module Name:	src
 Committed By:	nia
 Date:		Sat Sep 19 09:40:56 UTC 2026

 Modified Files:
 	src/tests/lib/libc/string: t_memchr.c

 Log Message:
 PR lib/60744 at least this test passes on i386


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/string/t_memchr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: src/tests/lib/libc/string
Date: Sun, 20 Sep 2026 17:35:55 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Sep 20 17:35:55 UTC 2026

 Modified Files:
 	src/tests/lib/libc/string: t_memchr.c

 Log Message:
 t_memchr: Sprinkle a few more NUL byte tests.

 PR lib/60744: memchr(3) is busticated


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/string/t_memchr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: src
Date: Sun, 20 Sep 2026 17:39:43 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Sep 20 17:39:43 UTC 2026

 Modified Files:
 	src/common/lib/libc/arch/x86_64/string: memchr.S
 	src/tests/lib/libc/string: t_memchr.c

 Log Message:
 amd64 memchr(3): Fix case when ptr + len wraps around address space.

 While here, give meaningful names to the various internal labels.

 PR lib/60744: memchr(3) is busticated


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.7 src/common/lib/libc/arch/x86_64/string/memchr.S
 cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/string/t_memchr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 20 Sep 2026 17:40:29 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-11, pullup-10


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: src/common/lib/libc/arch/x86_64/string
Date: Sun, 20 Sep 2026 17:43:13 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Sep 20 17:43:13 UTC 2026

 Modified Files:
 	src/common/lib/libc/arch/x86_64/string: memchr.S

 Log Message:
 amd64 memchr(3): Fix accidental spaces instead of tab.

 PR lib/60744: memchr(3) is busticated


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/arch/x86_64/string/memchr.S

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 21 Oct 2026 01:01:10 +0000
State-Changed-Why:
pullup-11 #544
pullup-10 #1389


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60744 CVS commit: [netbsd-11] src
Date: Sat, 24 Oct 2026 11:24:31 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Oct 24 11:24:30 UTC 2026

 Modified Files:
 	src/common/lib/libc/arch/x86_64/string [netbsd-11]: memchr.S
 	src/tests/lib/libc/string [netbsd-11]: Makefile t_memchr.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #544):

 	tests/lib/libc/string/Makefile: revision 1.16
 	common/lib/libc/arch/x86_64/string/memchr.S: revision 1.7
 	common/lib/libc/arch/x86_64/string/memchr.S: revision 1.8
 	tests/lib/libc/string/t_memchr.c: revision 1.4
 	tests/lib/libc/string/t_memchr.c: revision 1.5
 	tests/lib/libc/string/t_memchr.c: revision 1.6
 	tests/lib/libc/string/t_memchr.c: revision 1.7

 PR lib/60744 demonstrate memchr(3) is busticated with a test

 PR lib/60744 at least this test passes on i386

 t_memchr: Sprinkle a few more NUL byte tests.
 PR lib/60744: memchr(3) is busticated

 amd64 memchr(3): Fix case when ptr + len wraps around address space.
 While here, give meaningful names to the various internal labels.
 PR lib/60744: memchr(3) is busticated

 amd64 memchr(3): Fix accidental spaces instead of tab.
 PR lib/60744: memchr(3) is busticated


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.6.48.1 src/common/lib/libc/arch/x86_64/string/memchr.S
 cvs rdiff -u -r1.15 -r1.15.4.1 src/tests/lib/libc/string/Makefile
 cvs rdiff -u -r1.3 -r1.3.46.1 src/tests/lib/libc/string/t_memchr.c

 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/60744 CVS commit: [netbsd-10] src
Date: Sat, 24 Oct 2026 11:32:38 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Oct 24 11:32:37 UTC 2026

 Modified Files:
 	src/common/lib/libc/arch/x86_64/string [netbsd-10]: memchr.S
 	src/tests/lib/libc/string [netbsd-10]: t_memchr.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1389):

 	common/lib/libc/arch/x86_64/string/memchr.S: revision 1.7
 	common/lib/libc/arch/x86_64/string/memchr.S: revision 1.8
 	tests/lib/libc/string/t_memchr.c: revision 1.4
 	tests/lib/libc/string/t_memchr.c: revision 1.5
 	tests/lib/libc/string/t_memchr.c: revision 1.6
 	tests/lib/libc/string/t_memchr.c: revision 1.7
 	(all via patch)

 PR lib/60744 demonstrate memchr(3) is busticated with a test

 PR lib/60744 at least this test passes on i386

 t_memchr: Sprinkle a few more NUL byte tests.
 PR lib/60744: memchr(3) is busticated

 amd64 memchr(3): Fix case when ptr + len wraps around address space.
 While here, give meaningful names to the various internal labels.
 PR lib/60744: memchr(3) is busticated

 amd64 memchr(3): Fix accidental spaces instead of tab.
 PR lib/60744: memchr(3) is busticated


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.6.40.1 src/common/lib/libc/arch/x86_64/string/memchr.S
 cvs rdiff -u -r1.3 -r1.3.42.1 src/tests/lib/libc/string/t_memchr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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.