NetBSD Problem Report #59259
From woods@mail.weird.com Sun Apr 6 23:23:49 2025
Return-Path: <woods@mail.weird.com>
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 "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 0C6D71A9239
for <gnats-bugs@gnats.NetBSD.org>; Sun, 6 Apr 2025 23:23:48 +0000 (UTC)
Message-Id: <m1u1ZL6-00N5LCC@more.local>
Date: Sun, 6 Apr 2025 16:23:44 -0700 (PDT)
From: "Greg A. Woods" <woods@planix.ca>
Sender: "Greg A. Woods" <woods@mail.weird.com>
Reply-To: "Greg A. Woods" <woods@planix.ca>
To: gnats-bugs@NetBSD.org
Subject: mail will crash if given '-H' (without optarg) last
X-Send-Pr-Version: 3.95
>Number: 59259
>Category: bin
>Synopsis: mail will crash if given '-H' (without optarg) last
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Apr 06 23:25:00 +0000 2025
>Originator: Greg A. Woods
>Release: NetBSD 10.99.12
>Organization:
Planix, Inc.; Kelowna, BC; Canada
>Environment:
System: NetBSD 10.99.12
Architecture: x86_64
Machine: amd64
>Description:
If mail(1) is invoked with a '-H' flag given last, and without
any optarg (the ":x" flags), it will crash.
>How-To-Repeat:
(gdb) run -u root -H
Starting program: /usr/bin/mail -u root -H
Program received signal SIGSEGV, Segmentation fault.
0x000000000040d3b3 in get_Hflag (argv=argv@entry=0x0) at /Volumes/work/woods/g-NetBSD-src/usr.bin/mail/list.c:1357
warning: 1357 /Volumes/work/woods/g-NetBSD-src/usr.bin/mail/list.c: No such file or directory
(gdb) bt
#0 0x000000000040d3b3 in get_Hflag (argv=argv@entry=0x0) at /Volumes/work/woods/g-NetBSD-src/usr.bin/mail/list.c:1357
#1 0x0000000000565d21 in main (argc=4, argv=0x7f7fff86b328) at /Volumes/work/woods/g-NetBSD-src/usr.bin/mail/main.c:361
(gdb)
>Fix:
I think the bug was introduced in usr.bin/mail/list.c:1.24
(2006/10/31) with untested handling of the ':' return from
getopt(3).
diff --git a/usr.bin/mail/list.c b/usr.bin/mail/list.c
index 49267e9a5c13..b8bb22fd6258 100644
--- a/usr.bin/mail/list.c
+++ b/usr.bin/mail/list.c
@@ -1348,7 +1348,9 @@ get_Hflag(char **argv)
flags = ~CMMASK;
- if (optarg == NULL) /* We had an error, just get the flags. */
+ if (optarg == NULL) /* We had an error, just return the flags. */
+ return flags;
+ if (argv == NULL) /* No optarg was given, just return the flags. */
return flags;
if (*optarg != ':' || optarg == argv[optind - 1]) {
(Contact us)
$NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 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.