NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/59259: mail will crash if given '-H' (without optarg) last



>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]) {



Home | Main Index | Thread Index | Old Index