From nobody@FreeBSD.org  Tue Apr  7 20:45:22 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 996B8106568E
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  7 Apr 2009 20:45:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 871888FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  7 Apr 2009 20:45:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n37KjMuK013259
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 7 Apr 2009 20:45:22 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n37KjMxj013258;
	Tue, 7 Apr 2009 20:45:22 GMT
	(envelope-from nobody)
Message-Id: <200904072045.n37KjMxj013258@www.freebsd.org>
Date: Tue, 7 Apr 2009 20:45:22 GMT
From: Rafal Grodzinski <grodzix@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] pkg_info throws segmentation fault if given non-existent long option
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         133473
>Category:       bin
>Synopsis:       [patch] pkg_info(1) throws segmentation fault if given non-existent long option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 07 20:50:05 UTC 2009
>Closed-Date:    Wed Jun 17 17:36:19 UTC 2009
>Last-Modified:  Wed Jun 17 17:36:19 UTC 2009
>Originator:     Rafal Grodzinski
>Release:        7.1-Release
>Organization:
>Environment:
FreeBSD grodzix 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Thu Jan  1 14:37:25 UTC 2009     root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
pkg_info (usr.sbin/pkg_install/info) throws segmentation fault if non existent long option is provided.

Array struct option longopts[] in main.c isn't ended with {NULL, 0, NULL, 0} so getopt_long doesn't know where to stop and tries to read past the last element of the array.
>How-To-Repeat:
pkg_info --y
pkg_info --ble
>Fix:
Add {NULL, 0, NULL, 0} at the end of struct option longopts[] array in main.c

Patch attached with submission follows:

--- /usr/src/usr.sbin/pkg_install/info/main.c	2008-11-25 02:59:29.000000000 +0000
+++ main.c	2009-04-07 20:01:57.000000000 +0000
@@ -58,6 +58,7 @@
 	{ "verbose",	no_argument,		NULL,		'v' },
 	{ "version",	no_argument,		NULL,		'P' },
 	{ "which",	required_argument,	NULL,		'W' },
+	{ NULL,		0,			NULL,		0 },
 };
 
 int


>Release-Note:
>Audit-Trail:

From: Dan Naumov <dan.naumov@gmail.com>
To: bug-followup@FreeBSD.org, grodzix@gmail.com
Cc:  
Subject: Re: bin/133473: [patch] pkg_info(1) throws segmentation fault if 
	given non-existent long option
Date: Mon, 1 Jun 2009 00:36:22 +0300

 --0016e6407ed0e5d9ad046b3c19ad
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 I can confirm that this issue still persists as of 7.2-STABLE built on May
 30:
 
 [jago@agathon ~]$ uname -a
 FreeBSD agathon.localdomain 7.2-STABLE FreeBSD 7.2-STABLE #0: Sat May 30
 09:28:34 EEST 2009     root@agathon.localdomain:/usr/obj/usr/src/sys/GENERIC
 amd64
 
 [jago@agathon ~]$ pkg_info --h
 Segmentation fault: 11 (core dumped)
 
 --0016e6407ed0e5d9ad046b3c19ad
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 I can confirm that this issue still persists as of 7.2-STABLE built on May =
 30:<br><br>[jago@agathon ~]$ uname -a<br>FreeBSD agathon.localdomain 7.2-ST=
 ABLE FreeBSD 7.2-STABLE #0: Sat May 30 09:28:34 EEST 2009=A0=A0=A0=A0 root@=
 agathon.localdomain:/usr/obj/usr/src/sys/GENERIC=A0 amd64<br>
 <br>[jago@agathon ~]$ pkg_info --h<br>Segmentation fault: 11 (core dumped)<=
 br>
 
 --0016e6407ed0e5d9ad046b3c19ad--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/133473: commit references a PR
Date: Mon,  1 Jun 2009 21:27:07 +0000 (UTC)

 Author: jilles
 Date: Mon Jun  1 21:26:52 2009
 New Revision: 193273
 URL: http://svn.freebsd.org/changeset/base/193273
 
 Log:
   Fix segfault when giving invalid long option to pkg_info.
   
   PR:		bin/133473
   Submitted by:	Rafal Grodzinski
   Approved by:	ed (mentor)
   MFC after:	1 week
 
 Modified:
   head/usr.sbin/pkg_install/info/main.c
 
 Modified: head/usr.sbin/pkg_install/info/main.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/info/main.c	Mon Jun  1 21:17:03 2009	(r193272)
 +++ head/usr.sbin/pkg_install/info/main.c	Mon Jun  1 21:26:52 2009	(r193273)
 @@ -58,6 +58,7 @@ static struct option longopts[] = {
  	{ "verbose",	no_argument,		NULL,		'v' },
  	{ "version",	no_argument,		NULL,		'P' },
  	{ "which",	required_argument,	NULL,		'W' },
 +	{ NULL,		0,			NULL,		0 }
  };
  
  int
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/133473: commit references a PR
Date: Mon,  8 Jun 2009 22:06:07 +0000 (UTC)

 Author: jilles
 Date: Mon Jun  8 22:05:47 2009
 New Revision: 193776
 URL: http://svn.freebsd.org/changeset/base/193776
 
 Log:
   MFC r193273: Fix segfault when giving invalid long option to pkg_info.
   
   PR:		bin/133473
   Submitted by:	Rafal Grodzinski
   Approved by:	ed (mentor)
 
 Modified:
   stable/7/usr.sbin/pkg_install/   (props changed)
   stable/7/usr.sbin/pkg_install/info/main.c
 
 Modified: stable/7/usr.sbin/pkg_install/info/main.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/info/main.c	Mon Jun  8 22:03:37 2009	(r193775)
 +++ stable/7/usr.sbin/pkg_install/info/main.c	Mon Jun  8 22:05:47 2009	(r193776)
 @@ -58,6 +58,7 @@ static struct option longopts[] = {
  	{ "verbose",	no_argument,		NULL,		'v' },
  	{ "version",	no_argument,		NULL,		'P' },
  	{ "which",	required_argument,	NULL,		'W' },
 +	{ NULL,		0,			NULL,		0 }
  };
  
  int
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/133473: commit references a PR
Date: Wed, 17 Jun 2009 02:52:49 +0000 (UTC)

 Author: emaste
 Date: Wed Jun 17 02:52:35 2009
 New Revision: 194320
 URL: http://svn.freebsd.org/changeset/base/194320
 
 Log:
   MFC r193273 by jilles:
   
     Fix segfault when giving invalid long option to pkg_info.
   
   PR: bin/133473
   Submitted by: Rafal Grodzinski
 
 Modified:
   stable/6/usr.sbin/pkg_install/   (props changed)
   stable/6/usr.sbin/pkg_install/info/main.c
 
 Modified: stable/6/usr.sbin/pkg_install/info/main.c
 ==============================================================================
 --- stable/6/usr.sbin/pkg_install/info/main.c	Wed Jun 17 02:51:16 2009	(r194319)
 +++ stable/6/usr.sbin/pkg_install/info/main.c	Wed Jun 17 02:52:35 2009	(r194320)
 @@ -58,6 +58,7 @@ static struct option longopts[] = {
  	{ "verbose",	no_argument,		NULL,		'v' },
  	{ "version",	no_argument,		NULL,		'P' },
  	{ "which",	required_argument,	NULL,		'W' },
 +	{ NULL,		0,			NULL,		0 }
  };
  
  int
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Wed Jun 17 17:36:18 UTC 2009 
State-Changed-Why:  
Committed. Thanks! 

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