From nobody@FreeBSD.org  Tue Oct 23 22:19:37 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id EFAD8E22
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Oct 2012 22:19:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id BED0A8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Oct 2012 22:19:37 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9NMJbcc014854
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Oct 2012 22:19:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9NMJbfa014853;
	Tue, 23 Oct 2012 22:19:37 GMT
	(envelope-from nobody)
Message-Id: <201210232219.q9NMJbfa014853@red.freebsd.org>
Date: Tue, 23 Oct 2012 22:19:37 GMT
From: jb <jb.1234abcd@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: PW(8) - 'pw usermod' causes Segmentation fault: 11 (core dumped)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173005
>Category:       bin
>Synopsis:       [patch] pw(8) - 'pw usermod' causes Segmentation fault: 11 (core dumped)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bapt
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 23 22:20:00 UTC 2012
>Closed-Date:    Fri May 31 12:55:57 UTC 2013
>Last-Modified:  Fri May 31 12:55:57 UTC 2013
>Originator:     jb
>Release:        FreeBSD 9.1-RC2 #0
>Organization:
>Environment:
FreeBSD localhost.localdomain 9.1-RC2 FreeBSD 9.1-RC2 #0 r241133: Tue Oct  2 17:11:45 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
# pw usermod moo4 -g ""
Segmentation fault: 11 (core dumped)
#

>How-To-Repeat:
as above

>Fix:


>Release-Note:
>Audit-Trail:

From: Eitan Adler <lists@eitanadler.com>
To: jb <jb.1234abcd@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: bin/173005: PW(8) - 'pw usermod' causes Segmentation fault: 11
 (core dumped)
Date: Tue, 23 Oct 2012 23:17:33 -0400

 On 23 October 2012 18:19, jb <jb.1234abcd@gmail.com> wrote:
 >>Description:
 > # pw usermod moo4 -g ""
 > Segmentation fault: 11 (core dumped)
 
 note to the person who fixes this: this is reproducible as root on
 
 FreeBSD radar 10.0-CURRENT FreeBSD 10.0-CURRENT #1 r239951: Fri Aug 31
 10:32:27 PDT 2012     eitan@radar:/usr/obj/more/src/sys/GENERIC  amd64
 
 if the user exists.
 
 -- 
 Eitan Adler

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com, lists@eitanadler.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Sun, 28 Oct 2012 01:36:57 -0400

 --TB36FDmn/VVEgNH/
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Looks like this was introduced by r63596, which itself was a fix for
 bin/5717: http://www.freebsd.org/cgi/query-pr.cgi?pr=5717
 
 Basically, pw(8) allows '-g ""' when setting the default group for new
 users; it has a special meaning, described in the man page. I think the
 right fix is to check for -D before proceeding when running with -g "".
 With the attached patch, 'pw useradd -D -g ""' still does the right
 thing, and we also have
 
 # pw usermod mark -g ""
 pw: group `' does not exist
 #
 
 which I think is the right behaviour.
 
 Thanks,
 -Mark
 
 --TB36FDmn/VVEgNH/
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="pw_empty_group.patch"
 
 diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
 index 1b72cbd..26d13cf 100644
 --- a/usr.sbin/pw/pw_user.c
 +++ b/usr.sbin/pw/pw_user.c
 @@ -228,7 +228,8 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
  		cnf->password_days = atoi(arg->val);
  
  	if ((arg = getarg(args, 'g')) != NULL) {
 -		if (!*(p = arg->val))	/* Handle empty group list specially */
 +		/* Handle empty group list specially when defining a default group. */
 +		if (!*(p = arg->val) && getarg(args, 'D'))
  			cnf->default_group = "";
  		else {
  			if ((grp = GETGRNAM(p)) == NULL) {
 
 --TB36FDmn/VVEgNH/--

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Sun, 28 Oct 2012 10:03:36 +0100

 Well done, except for error message.
 
 It should be:
 # pw usermod mark -g ""
 pw: group `' is not defined
 
 which would be consistent with:
 # pw useradd mark -g ""
 pw: group `' is not defined
 
 jb

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Sun, 28 Oct 2012 14:53:29 -0400

 With my patch the error message is consistent:
 
 # pw useradd mark -g ""
 pw: group `' does not exist
 # pw usermod mark -g ""
 pw: group `' does not exist
 #

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Sun, 28 Oct 2012 20:41:50 +0100

 This is the current (unpatched) state:
 
 # pw useradd moo -g moo
 pw: group `moo' does not exist
 # pw useradd moo -g boo
 pw: group `boo' does not exist
 # pw useradd moo -g ""
 pw: group `' is not defined
 
 As you can see there is a distinction between error msgs
 based on user input of primary group (or lack of it).
 That's why I asked you to be consistent with past and
 current user experience.
 jb

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Mon, 29 Oct 2012 00:15:55 -0400

 The error messages aren't different by design though - the different
 behaviour for -g "" is a side-effect of the change I mentioned in the
 first email. There is no practical distinction between those two errors
 anyway - they come from two essentially identical checks at different points
 in the code.
 
 In fact, the "... is not defined" check is redundant and can be
 removed/simplified if my patch is applied. Specifically, that check only
 fails with -g "" in the unpatched pw(8).
 
 -Mark

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jb.1234abcd@gmail.com
Cc:  
Subject: Re: bin/173005: PW(8) - &#39;pw usermod&#39; causes Segmentation
 fault: 11 (core dumped)
Date: Mon, 29 Oct 2012 07:15:10 +0100

 Simplifying for user is good.
 So, go ahead - that segmentation fault looks bad :-)
 jb
Responsible-Changed-From-To: freebsd-bugs->bapt 
Responsible-Changed-By: bapt 
Responsible-Changed-When: Tue Oct 30 08:11:28 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173005 
State-Changed-From-To: open->closed 
State-Changed-By: bapt 
State-Changed-When: Fri May 31 12:55:56 UTC 2013 
State-Changed-Why:  
This has been fixed long ago, forgot to close, thanks for reporting 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173005 
>Unformatted:
