NetBSD Problem Report #59991

From www@netbsd.org  Tue Feb 10 04:22:24 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)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "R13" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id AB3B61A923D
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 10 Feb 2026 04:22:23 +0000 (UTC)
Message-Id: <20260210042222.9FE131A923E@mollari.NetBSD.org>
Date: Tue, 10 Feb 2026 04:22:22 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: pkg_add: null pointer deref in pkg_add -m parsing
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         59991
>Category:       pkg
>Synopsis:       pkg_add: null pointer deref in pkg_add -m parsing
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bsiegert
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 10 04:25:00 +0000 2026
>Closed-Date:    Tue Jun 30 13:40:10 +0000 2026
>Last-Modified:  Tue Jun 30 13:40:10 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11
>Organization:
The NetBSD/arch Version Foundacrash, Inc.
>Environment:
>Description:
The pkg_add -m option crashes on null pointer dereference if the input has a slash but then no space.

This is because I accidentally mixed the strchr and strchrnul idioms, and only fixed it in one case, not the other:
        /*
         * If there's no /, treat it as a single MACHINE_ARCH.
         */
        if ((q = strchr(p, '/')) == NULL) {
                *machine_arch = copy;
                *opsys = NULL;
                *os_version = NULL;
        } else {
...
                /*
                 * If there's no SPC, fail.
                 */
                if (*(r = strchr(q, ' ')) == '\0') {
                        goto fail;
                }
>How-To-Repeat:
pkg_add -m 'foo/bar'
>Fix:
The first strchr is good; the second should be

                if ((r = strchr(q, ' ')) == NULL) {
                        goto fail;
                }

(Or, the second should be strchrnul to make the test work, but let's just use strchr for consistency.)

>Release-Note:

>Audit-Trail:
From: "Benny Siegert" <bsiegert@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59991 CVS commit: pkgsrc/pkgtools/pkg_install/files
Date: Sat, 28 Feb 2026 09:49:35 +0000

 Module Name:	pkgsrc
 Committed By:	bsiegert
 Date:		Sat Feb 28 09:49:35 UTC 2026

 Modified Files:
 	pkgsrc/pkgtools/pkg_install/files/add: parse_cross.c
 	pkgsrc/pkgtools/pkg_install/files/lib: version.h

 Log Message:
 pkg_install: fix null pointer dereference

 The pkg_add -m option crashes on null pointer dereference if the input has a
 slash but then no space.

 Patch by riastradh@ in PR pkg/59991.


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 pkgsrc/pkgtools/pkg_install/files/add/parse_cross.c
 cvs rdiff -u -r1.201 -r1.202 pkgsrc/pkgtools/pkg_install/files/lib/version.h

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

Responsible-Changed-From-To: pkg-manager->bsiegert
Responsible-Changed-By: bsiegert@NetBSD.org
Responsible-Changed-When: Sat, 28 Feb 2026 10:09:51 +0000
Responsible-Changed-Why:
Patch applied.

Will also import this into src.


From: "Benny Siegert" <bsiegert@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59991 CVS commit: src/external/bsd/pkg_install/dist
Date: Sat, 28 Feb 2026 10:34:20 +0000

 Module Name:	src
 Committed By:	bsiegert
 Date:		Sat Feb 28 10:34:20 UTC 2026

 Update of /cvsroot/src/external/bsd/pkg_install/dist
 In directory ivanova.netbsd.org:/tmp/cvs-serv11297

 Log Message:
 Import pkg_install 20260227 from pkgsrc

 Contains the fix for PR pkg/59991

 Status:

 Vendor Tag:	PKGSRC
 Release Tags:	pkg_install-20260227

 U src/external/bsd/pkg_install/dist/add/add.h
 U src/external/bsd/pkg_install/dist/add/main.c
 U src/external/bsd/pkg_install/dist/add/perform.c
 U src/external/bsd/pkg_install/dist/add/pkg_add.1
 U src/external/bsd/pkg_install/dist/add/parse_cross.c
 U src/external/bsd/pkg_install/dist/admin/admin.h
 U src/external/bsd/pkg_install/dist/admin/audit-packages.8
 U src/external/bsd/pkg_install/dist/admin/audit-packages.sh.in
 U src/external/bsd/pkg_install/dist/admin/audit.c
 U src/external/bsd/pkg_install/dist/admin/check.c
 U src/external/bsd/pkg_install/dist/admin/download-vulnerability-list.8
 U src/external/bsd/pkg_install/dist/admin/download-vulnerability-list.sh.in
 U src/external/bsd/pkg_install/dist/admin/main.c
 U src/external/bsd/pkg_install/dist/admin/pkg_admin.1
 U src/external/bsd/pkg_install/dist/create/build.c
 U src/external/bsd/pkg_install/dist/create/create.h
 U src/external/bsd/pkg_install/dist/create/main.c
 U src/external/bsd/pkg_install/dist/create/perform.c
 U src/external/bsd/pkg_install/dist/create/pkg_create.1
 U src/external/bsd/pkg_install/dist/create/pl.c
 U src/external/bsd/pkg_install/dist/create/util.c
 U src/external/bsd/pkg_install/dist/delete/pkg_delete.1
 U src/external/bsd/pkg_install/dist/delete/pkg_delete.c
 U src/external/bsd/pkg_install/dist/info/info.h
 U src/external/bsd/pkg_install/dist/info/main.c
 U src/external/bsd/pkg_install/dist/info/perform.c
 U src/external/bsd/pkg_install/dist/info/show.c
 C src/external/bsd/pkg_install/dist/info/pkg_info.1
 U src/external/bsd/pkg_install/dist/lib/automatic.c
 U src/external/bsd/pkg_install/dist/lib/config.h.in
 U src/external/bsd/pkg_install/dist/lib/conflicts.c
 U src/external/bsd/pkg_install/dist/lib/defs.h
 U src/external/bsd/pkg_install/dist/lib/dewey.c
 U src/external/bsd/pkg_install/dist/lib/dewey.h
 U src/external/bsd/pkg_install/dist/lib/fexec.c
 U src/external/bsd/pkg_install/dist/lib/file.c
 U src/external/bsd/pkg_install/dist/lib/global.c
 U src/external/bsd/pkg_install/dist/lib/gpgsig.c
 U src/external/bsd/pkg_install/dist/lib/iterate.c
 U src/external/bsd/pkg_install/dist/lib/lib.h
 U src/external/bsd/pkg_install/dist/lib/license.c
 U src/external/bsd/pkg_install/dist/lib/lpkg.c
 U src/external/bsd/pkg_install/dist/lib/opattern.c
 U src/external/bsd/pkg_install/dist/lib/parse-config.c
 U src/external/bsd/pkg_install/dist/lib/pkcs7.c
 U src/external/bsd/pkg_install/dist/lib/pkg_install.conf.5.in
 U src/external/bsd/pkg_install/dist/lib/pkg_io.c
 U src/external/bsd/pkg_install/dist/lib/pkg_signature.c
 U src/external/bsd/pkg_install/dist/lib/pkg_summary.5
 U src/external/bsd/pkg_install/dist/lib/pkgdb.c
 U src/external/bsd/pkg_install/dist/lib/pkgsrc.7
 U src/external/bsd/pkg_install/dist/lib/plist.c
 U src/external/bsd/pkg_install/dist/lib/remove.c
 U src/external/bsd/pkg_install/dist/lib/str.c
 U src/external/bsd/pkg_install/dist/lib/var.c
 U src/external/bsd/pkg_install/dist/lib/version.c
 U src/external/bsd/pkg_install/dist/lib/vulnerabilities-file.c
 U src/external/bsd/pkg_install/dist/lib/xwrapper.c
 C src/external/bsd/pkg_install/dist/lib/version.h
 U src/external/bsd/pkg_install/dist/x509/pkgsrc.cnf
 U src/external/bsd/pkg_install/dist/x509/pkgsrc.sh
 U src/external/bsd/pkg_install/dist/x509/signing.txt

 2 conflicts created by this import.
 Use the following command to help the merge:

 	cvs checkout -jPKGSRC:yesterday -jPKGSRC src/external/bsd/pkg_install/dist

From: "Benny Siegert" <bsiegert@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59991 CVS commit: src/external/bsd/pkg_install/dist
Date: Sat, 28 Feb 2026 10:40:56 +0000

 Module Name:	src
 Committed By:	bsiegert
 Date:		Sat Feb 28 10:40:55 UTC 2026

 Modified Files:
 	src/external/bsd/pkg_install/dist/info: pkg_info.1
 	src/external/bsd/pkg_install/dist/lib: version.h

 Log Message:
 Merge pkg_install-20260226

 For PR pkg/59991


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/external/bsd/pkg_install/dist/info/pkg_info.1
 cvs rdiff -u -r1.24 -r1.25 src/external/bsd/pkg_install/dist/lib/version.h

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

State-Changed-From-To: open->closed
State-Changed-By: bsiegert@NetBSD.org
State-Changed-When: Sat, 28 Feb 2026 16:16:06 +0000
State-Changed-Why:
All done!

Or would you like a pullup to NetBSD-11?


State-Changed-From-To: closed->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 28 Feb 2026 19:16:52 +0000
State-Changed-Why:
needs pullup-11, maybe pullup-10 and pullup-9 if applicable


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 29 Jun 2026 20:09:10 +0000
State-Changed-Why:
fixed in HEAD
pullup-11 #355 https://releng.netbsd.org/cgi-bin/req-11.cgi?show=355
inapplicable <11, code is new since 10


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59991 CVS commit: [netbsd-11] src/external/bsd/pkg_install
Date: Tue, 30 Jun 2026 09:48:45 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Jun 30 09:48:45 UTC 2026

 Modified Files:
 	src/external/bsd/pkg_install/dist/add [netbsd-11]: parse_cross.c
 	src/external/bsd/pkg_install/dist/info [netbsd-11]: pkg_info.1
 	src/external/bsd/pkg_install/dist/lib [netbsd-11]: version.h
 	src/external/bsd/pkg_install/lib [netbsd-11]: Makefile
 	src/external/bsd/pkg_install/sbin [netbsd-11]: Makefile.inc

 Log Message:
 Pull up the following, requested by riastradh in ticket #355:

 	external/bsd/pkg_install/dist/add/parse_cross.c up to 1.1.1.2
 	external/bsd/pkg_install/dist/info/pkg_info.1   up to 1.5
 	external/bsd/pkg_install/dist/lib/version.h     up to 1.25
 	external/bsd/pkg_install/lib/Makefile           up to 1.12
 	external/bsd/pkg_install/sbin/Makefile.inc      up to 1.6

 Sync pkg_install with HEAD.
 PR kern/59991: pkg_add: null pointer deref in pkg_add -m parsing.


 To generate a diff of this commit:
 cvs rdiff -u -r1.1.1.1 -r1.1.1.1.4.1 \
     src/external/bsd/pkg_install/dist/add/parse_cross.c
 cvs rdiff -u -r1.4 -r1.4.10.1 \
     src/external/bsd/pkg_install/dist/info/pkg_info.1
 cvs rdiff -u -r1.24 -r1.24.2.1 \
     src/external/bsd/pkg_install/dist/lib/version.h
 cvs rdiff -u -r1.11 -r1.11.10.1 src/external/bsd/pkg_install/lib/Makefile
 cvs rdiff -u -r1.5 -r1.5.26.1 src/external/bsd/pkg_install/sbin/Makefile.inc

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

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 30 Jun 2026 13:40:10 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 11, inapplicable <11


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