From nobody@FreeBSD.org  Tue Aug 11 06:16:54 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 C370C106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 11 Aug 2009 06:16:54 +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 B28408FC1F
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 11 Aug 2009 06:16:54 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n7B6Gsgk017103
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 11 Aug 2009 06:16:54 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n7B6GsE4017102;
	Tue, 11 Aug 2009 06:16:54 GMT
	(envelope-from nobody)
Message-Id: <200908110616.n7B6GsE4017102@www.freebsd.org>
Date: Tue, 11 Aug 2009 06:16:54 GMT
From: "Andrey V. Elsukov" <bu7cher@yandex.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [geom][patch] gpart drops core when adding partition to non-existent geom
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         137656
>Category:       bin
>Synopsis:       [geom][patch] gpart drops core when adding partition to non-existent geom
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-geom
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 11 06:20:02 UTC 2009
>Closed-Date:    Mon Aug 17 04:49:52 UTC 2009
>Last-Modified:  Mon Aug 17 04:49:52 UTC 2009
>Originator:     Andrey V. Elsukov
>Release:        8.0-BETA2
>Organization:
>Environment:
8.0-BETA2 FreeBSD 8.0-BETA2 #0: Wed Jul 15 21:48:41 UTC 2009     root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
gpart crashes when adding partitions to non-existent geom.
Problem is in gpart_autofill function. It doesn't check returned value after calling find_geom(). And next function doing access to NULL pointer.

>How-To-Repeat:
> gpart show
=>       34  312581741  ad4  GPT  (149G)
         34        256    1  freebsd-boot  (128K)
        290    4194304    2  freebsd-swap  (2.0G)
    4194594  125829120    3  freebsd-zfs  (60G)
  130023714  182558061       - free -  (87G)
> sudo gpart add -t freebsd-zfs ad6
Segmentation fault (core dumped)

>Fix:
After my patch:
> sudo ./gpart add -t freebsd-zfs ad6
gpart: No such geom: ad6.


Patch attached with submission follows:

--- src/sbin/geom/class/part/geom_part.c	2009-07-14 12:54:23.444482747 +0400
+++ src/sbin/geom/class/part/geom_part.c	2009-08-11 09:58:13.246739711 +0400
@@ -275,7 +275,10 @@
 	if (error)
 		return (error);
 	cp = find_class(&mesh, gctl_get_ascii(req, "class"));
-	gp = find_geom(cp, gctl_get_ascii(req, "geom"));
+	s = gctl_get_ascii(req, "geom");
+	gp = find_geom(cp, s);
+	if (gp == NULL)
+		errx(EXIT_FAILURE, "No such geom: %s.", s);
 	first = atoll(find_geomcfg(gp, "first"));
 	last = atoll(find_geomcfg(gp, "last"));
 	grade = ~0ULL;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Aug 11 07:13:25 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=137656 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Mon Aug 17 04:49:37 UTC 2009 
State-Changed-Why:  
Committed. 

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