NetBSD Problem Report #57888
From www@netbsd.org Mon Jan 29 15:10:33 2024
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))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 3FB571A9238
for <gnats-bugs@gnats.NetBSD.org>; Mon, 29 Jan 2024 15:10:33 +0000 (UTC)
Message-Id: <20240129151032.338EA1A9239@mollari.NetBSD.org>
Date: Mon, 29 Jan 2024 15:10:32 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: pkg_create fails ungracefully if uid or gid on file doesn't have name
X-Send-Pr-Version: www-1.0
>Number: 57888
>Category: pkg
>Synopsis: pkg_create fails ungracefully if uid or gid on file doesn't have name
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: jkoshy
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 29 15:15:00 +0000 2024
>Closed-Date: Sat Feb 03 15:10:13 +0000 2024
>Last-Modified: Sat Feb 03 15:10:13 +0000 2024
>Originator: Taylor R Campbell
>Release: current
>Organization:
The NetBSD pkg_installation
>Environment:
>Description:
(gdb) run
Starting program: /usr/sbin/pkg_create -K /usr/pkg/pkgdb -l -U -B /usr/pkgsrc/mail/imp/work/.pkgdb/+BUILD_INFO -b /usr/pkgsrc/mail/imp/work/.pkgdb/+BUILD_VERSION -c /usr/pkgsrc/mail/imp/work/.pkgdb/+COMMENT -D /usr/pkgsrc/mail/imp/work/.pkgdb/+DISPLAY -d /usr/pkgsrc/mail/imp/work/.pkgdb/+DESC -f /usr/pkgsrc/mail/imp/work/.PLIST_deps -S /usr/pkgsrc/mail/imp/work/.pkgdb/+SIZE_ALL -s /usr/pkgsrc/mail/imp/work/.pkgdb/+SIZE_PKG -C imp-3.\* -i /usr/pkgsrc/mail/imp/work/.pkgdb/+INSTALL -k /usr/pkgsrc/mail/imp/work/.pkgdb/+DEINSTALL -F gzip -I /usr/pkg -p /usr/pkgsrc/mail/imp/work/.destdir/usr/pkg /usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp.tgz
Program received signal SIGSEGV, Segmentation fault.
0x000073151d783a10 in strlen () from /usr/lib/libc.so.12
(gdb) bt
#0 0x000073151d783a10 in strlen () from /usr/lib/libc.so.12
#1 0x000073151d6b0ba5 in _strdup (str=0x0)
at /usr/src/lib/libc/string/strdup.c:60
#2 0x000000014cc09b70 in xstrdup (str=<optimized out>)
at /usr/src/external/bsd/pkg_install/dist/lib/xwrapper.c:99
#3 0x000000014cc043af in update_ids (file=file@entry=0x73152076c1c0)
at /usr/src/external/bsd/pkg_install/dist/create/util.c:78
#4 0x000000014cc045ac in load_memory_file (
disk_name=0x7f7fffde7d97 "/usr/pkgsrc/mail/imp/work/.pkgdb/+INSTALL",
archive_name=archive_name@entry=0x14cc0a72d "+INSTALL",
owner=<optimized out>, group=<optimized out>, mode=mode@entry=365)
at /usr/src/external/bsd/pkg_install/dist/create/util.c:128
#5 0x000000014cc04c54 in load_and_add (perm=365,
target_name=0x14cc0a72d "+INSTALL", input_name=<optimized out>,
plist=0x7f7fffde7480)
at /usr/src/external/bsd/pkg_install/dist/create/build.c:338
#6 pkg_build (
pkg=pkg@entry=0x731520796000 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp",
full_pkg=full_pkg@entry=0x7f7fffde7e32 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp.tgz", suffix=suffix@entry=0x7f7fffde7e68 "tgz",
plist=plist@entry=0x7f7fffde7480)
at /usr/src/external/bsd/pkg_install/dist/create/build.c:373
#7 0x000000014cc03d5c in pkg_perform (
pkg=0x731520796000 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp")
at /usr/src/external/bsd/pkg_install/dist/create/perform.c:228
#8 0x000000014cc09e0b in main (argc=1, argv=0x7f7fffde7640)
at /usr/src/external/bsd/pkg_install/dist/create/main.c:202
(gdb) fr 3
#3 0x000000014cc043af in update_ids (file=file@entry=0x73152076c1c0)
at /usr/src/external/bsd/pkg_install/dist/create/util.c:78
78 file->group = xstrdup(group_from_gid(file->st.st_gid, 1));
(gdb) info locals
No locals.
(gdb) print *file
$1 = {st = {st_dev = 43009, st_mode = 33261, st_ino = 55666008, st_nlink = 1,
st_uid = 0, st_gid = 125, st_rdev = 18446744073709551615, st_atim = {
tv_sec = 1706487457, tv_nsec = 804541539}, st_mtim = {
tv_sec = 1706487457, tv_nsec = 804745331}, st_ctim = {
tv_sec = 1706487457, tv_nsec = 804745331}, st_birthtim = {
tv_sec = 1706487457, tv_nsec = 804539974}, st_size = 24531,
st_blocks = 48, st_blksize = 32768, st_flags = 0, st_gen = 0, st_spare = {
0, 0}}, name = 0x14cc0a72d "+INSTALL", owner = 0x7315207a60e8 "root",
group = 0x0, mode = 365, data = 0x0, len = 0}
>How-To-Repeat:
1. chown/chgrp pkgsrc files to a uid/gid without a name in /etc/passwd or /etc/group
2. try to build a package
(Realistically, what happened is that /etc/group got munged by etcupdate(8), causing the wsrc gid to change.)
>Fix:
Yes, please!
At the very least, pkg_create should fail with an obvious error message, not with a SIGSEGV and core dump.
>Release-Note:
>Audit-Trail:
From: sunil@nimmagadda.net
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: pkg/57888: pkg_create fails ungracefully if uid or gid on file
doesn't have name
Date: Tue, 30 Jan 2024 04:52:10 +0530
campbell+netbsd@mumble.net writes:
>>Number: 57888
>>Category: pkg
>>Synopsis: pkg_create fails ungracefully if uid or gid on file doesn't have name
>>Confidential: no
>>Severity: serious
>>Priority: medium
>>Responsible: pkg-manager
>>State: open
>>Class: sw-bug
>>Submitter-Id: net
>>Arrival-Date: Mon Jan 29 15:15:00 +0000 2024
>>Originator: Taylor R Campbell
>>Release: current
>>Organization:
> The NetBSD pkg_installation
>>Environment:
>>Description:
> (gdb) run
> Starting program: /usr/sbin/pkg_create -K /usr/pkg/pkgdb -l -U -B /usr/pkgsrc/mail/imp/work/.pkgdb/+BUILD_INFO -b /usr/pkgsrc/mail/imp/work/.pkgdb/+BUILD_VERSION -c /usr/pkgsrc/mail/imp/work/.pkgdb/+COMMENT -D /usr/pkgsrc/mail/imp/work/.pkgdb/+DISPLAY -d /usr/pkgsrc/mail/imp/work/.pkgdb/+DESC -f /usr/pkgsrc/mail/imp/work/.PLIST_deps -S /usr/pkgsrc/mail/imp/work/.pkgdb/+SIZE_ALL -s /usr/pkgsrc/mail/imp/work/.pkgdb/+SIZE_PKG -C imp-3.\* -i /usr/pkgsrc/mail/imp/work/.pkgdb/+INSTALL -k /usr/pkgsrc/mail/imp/work/.pkgdb/+DEINSTALL -F gzip -I /usr/pkg -p /usr/pkgsrc/mail/imp/work/.destdir/usr/pkg /usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp.tgz
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x000073151d783a10 in strlen () from /usr/lib/libc.so.12
> (gdb) bt
> #0 0x000073151d783a10 in strlen () from /usr/lib/libc.so.12
> #1 0x000073151d6b0ba5 in _strdup (str=0x0)
> at /usr/src/lib/libc/string/strdup.c:60
> #2 0x000000014cc09b70 in xstrdup (str=<optimized out>)
> at /usr/src/external/bsd/pkg_install/dist/lib/xwrapper.c:99
> #3 0x000000014cc043af in update_ids (file=file@entry=0x73152076c1c0)
> at /usr/src/external/bsd/pkg_install/dist/create/util.c:78
> #4 0x000000014cc045ac in load_memory_file (
> disk_name=0x7f7fffde7d97 "/usr/pkgsrc/mail/imp/work/.pkgdb/+INSTALL",
> archive_name=archive_name@entry=0x14cc0a72d "+INSTALL",
> owner=<optimized out>, group=<optimized out>, mode=mode@entry=365)
> at /usr/src/external/bsd/pkg_install/dist/create/util.c:128
> #5 0x000000014cc04c54 in load_and_add (perm=365,
> target_name=0x14cc0a72d "+INSTALL", input_name=<optimized out>,
> plist=0x7f7fffde7480)
> at /usr/src/external/bsd/pkg_install/dist/create/build.c:338
> #6 pkg_build (
> pkg=pkg@entry=0x731520796000 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp",
> full_pkg=full_pkg@entry=0x7f7fffde7e32 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp.tgz", suffix=suffix@entry=0x7f7fffde7e68 "tgz",
> plist=plist@entry=0x7f7fffde7480)
> at /usr/src/external/bsd/pkg_install/dist/create/build.c:373
> #7 0x000000014cc03d5c in pkg_perform (
> pkg=0x731520796000 "/usr/pkgsrc/mail/imp/work/.packages/imp-4.3.11nb2.tmp")
> at /usr/src/external/bsd/pkg_install/dist/create/perform.c:228
> #8 0x000000014cc09e0b in main (argc=1, argv=0x7f7fffde7640)
> at /usr/src/external/bsd/pkg_install/dist/create/main.c:202
> (gdb) fr 3
> #3 0x000000014cc043af in update_ids (file=file@entry=0x73152076c1c0)
> at /usr/src/external/bsd/pkg_install/dist/create/util.c:78
> 78 file->group = xstrdup(group_from_gid(file->st.st_gid, 1));
> (gdb) info locals
> No locals.
> (gdb) print *file
> $1 = {st = {st_dev = 43009, st_mode = 33261, st_ino = 55666008, st_nlink = 1,
> st_uid = 0, st_gid = 125, st_rdev = 18446744073709551615, st_atim = {
> tv_sec = 1706487457, tv_nsec = 804541539}, st_mtim = {
> tv_sec = 1706487457, tv_nsec = 804745331}, st_ctim = {
> tv_sec = 1706487457, tv_nsec = 804745331}, st_birthtim = {
> tv_sec = 1706487457, tv_nsec = 804539974}, st_size = 24531,
> st_blocks = 48, st_blksize = 32768, st_flags = 0, st_gen = 0, st_spare = {
> 0, 0}}, name = 0x14cc0a72d "+INSTALL", owner = 0x7315207a60e8 "root",
> group = 0x0, mode = 365, data = 0x0, len = 0}
>>How-To-Repeat:
> 1. chown/chgrp pkgsrc files to a uid/gid without a name in /etc/passwd or /etc/group
> 2. try to build a package
>
> (Realistically, what happened is that /etc/group got munged by etcupdate(8), causing the wsrc gid to change.)
>>Fix:
> Yes, please!
>
> At the very least, pkg_create should fail with an obvious error message, not with a SIGSEGV and core dump.
Fail with an obvious error message...
diff --git a/external/bsd/pkg_install/dist/create/util.c b/external/bsd/pkg_install/dist/create/util.c
--- a/external/bsd/pkg_install/dist/create/util.c
+++ b/external/bsd/pkg_install/dist/create/util.c
@@ -58,14 +58,18 @@
static void
update_ids(struct memory_file *file)
{
+ const char *s;
+
if (file->owner != NULL) {
uid_t uid;
if (uid_from_user(file->owner, &uid) == -1)
errx(2, "user %s unknown", file->owner);
file->st.st_uid = uid;
- } else {
- file->owner = xstrdup(user_from_uid(file->st.st_uid, 1));
+ } else {
+ if ((s = user_from_uid(file->st.st_uid, 1)) == NULL)
+ errx(2, "unknown user name");
+ file->owner = xstrdup(s);
}
if (file->group != NULL) {
@@ -75,7 +79,9 @@
errx(2, "group %s unknown", file->group);
file->st.st_gid = gid;
} else {
- file->group = xstrdup(group_from_gid(file->st.st_gid, 1));
+ if ((s = group_from_gid(file->st.st_gid, 1)) == NULL)
+ errx(2, "unknown group name");
+ file->group = xstrdup(s);
}
}
State-Changed-From-To: open->analyzed
State-Changed-By: jkoshy@NetBSD.org
State-Changed-When: Fri, 02 Feb 2024 14:37:19 +0000
State-Changed-Why:
A potential fix is now available.
From: Sunil Nimmagadda <sunil@nimmagadda.net>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: pkg/57888 (pkg_create fails ungracefully if uid or gid on file
doesn't have name)
Date: Fri, 02 Feb 2024 09:58:27 +0530
jkoshy@NetBSD.org writes:
> Synopsis: pkg_create fails ungracefully if uid or gid on file doesn't have name
>
> State-Changed-From-To: open->analyzed
> State-Changed-By: jkoshy@NetBSD.org
> State-Changed-When: Fri, 02 Feb 2024 14:37:19 +0000
> State-Changed-Why:
> A potential fix is now available.
Updated diff to include uid/gid in the error message...
diff --git a/external/bsd/pkg_install/dist/create/util.c b/external/bsd/pkg_install/dist/create/util.c
--- a/external/bsd/pkg_install/dist/create/util.c
+++ b/external/bsd/pkg_install/dist/create/util.c
@@ -58,14 +58,19 @@
static void
update_ids(struct memory_file *file)
{
+ const char *s;
+
if (file->owner != NULL) {
uid_t uid;
if (uid_from_user(file->owner, &uid) == -1)
errx(2, "user %s unknown", file->owner);
file->st.st_uid = uid;
- } else {
- file->owner = xstrdup(user_from_uid(file->st.st_uid, 1));
+ } else {
+ if ((s = user_from_uid(file->st.st_uid, 1)) == NULL)
+ errx(2, "unknown user name for uid %u",
+ file->st.st_uid);
+ file->owner = xstrdup(s);
}
if (file->group != NULL) {
@@ -75,7 +80,10 @@
errx(2, "group %s unknown", file->group);
file->st.st_gid = gid;
} else {
- file->group = xstrdup(group_from_gid(file->st.st_gid, 1));
+ if ((s = group_from_gid(file->st.st_gid, 1)) == NULL)
+ errx(2, "unknown group name for gid %u",
+ file->st.st_gid);
+ file->group = xstrdup(s);
}
}
Responsible-Changed-From-To: pkg-manager->jkoshy
Responsible-Changed-By: jkoshy@NetBSD.org
Responsible-Changed-When: Fri, 02 Feb 2024 17:13:59 +0000
Responsible-Changed-Why:
I will take a look.
From: "Joseph Koshy" <jkoshy@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57888 CVS commit: pkgsrc/pkgtools/pkg_install/files/create
Date: Sat, 3 Feb 2024 10:58:37 +0000
Module Name: pkgsrc
Committed By: jkoshy
Date: Sat Feb 3 10:58:37 UTC 2024
Modified Files:
pkgsrc/pkgtools/pkg_install/files/create: util.c
Log Message:
pkg_create: fail gracefully on encountering nameless uids and gids.
PR pkg/57888
Submitted by: Sunil Nimmagadda
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 pkgsrc/pkgtools/pkg_install/files/create/util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: analyzed->feedback
State-Changed-By: jkoshy@NetBSD.org
State-Changed-When: Sat, 03 Feb 2024 11:49:46 +0000
State-Changed-Why:
Fixed in r1.9 of pkgsrc/pkgtools/pkg_install/files/create/util.c.
State-Changed-From-To: feedback->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 03 Feb 2024 15:10:13 +0000
State-Changed-Why:
Thanks for taking care of this!
>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.