From owner-svn-src-all@FreeBSD.ORG  Sun Feb 26 22:09:22 2012
Return-Path: <owner-svn-src-all@FreeBSD.ORG>
Delivered-To: svn-src-all@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5FEED106566B;
	Sun, 26 Feb 2012 22:09:22 +0000 (UTC)
	(envelope-from nwhitehorn@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 30F318FC08;
	Sun, 26 Feb 2012 22:09:22 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q1QM9MqB085092;
	Sun, 26 Feb 2012 22:09:22 GMT
	(envelope-from nwhitehorn@svn.freebsd.org)
Received: (from nwhitehorn@localhost)
	by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1QM9LdP085089;
	Sun, 26 Feb 2012 22:09:21 GMT
	(envelope-from nwhitehorn@svn.freebsd.org)
Message-Id: <201202262209.q1QM9LdP085089@svn.freebsd.org>
From: Nathan Whitehorn <nwhitehorn@FreeBSD.org>
Date: Sun, 26 Feb 2012 22:09:21 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-head@freebsd.org
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r232200 - in head/usr.sbin/bsdinstall: distextract
	distfetch
X-BeenThere: svn-src-all@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
	user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-all>,
	<mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all>
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-all>,
	<mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 26 Feb 2012 22:09:22 -0000

Author: nwhitehorn
Date: Sun Feb 26 22:09:21 2012
New Revision: 232200
URL: http://svn.freebsd.org/changeset/base/232200

Log:
  Fix segfault if distfetch and distextract binaries are run standalone
  without the DISTRIBUTIONS environment variable set.
  
  PR:		bin/165492
  Submitted by:	Fernando Apesteguia
  MFC after:	4 days

Modified:
  head/usr.sbin/bsdinstall/distextract/distextract.c
  head/usr.sbin/bsdinstall/distfetch/distfetch.c

Modified: head/usr.sbin/bsdinstall/distextract/distextract.c
==============================================================================
--- head/usr.sbin/bsdinstall/distextract/distextract.c	Sun Feb 26 21:24:27 2012	(r232199)
+++ head/usr.sbin/bsdinstall/distextract/distextract.c	Sun Feb 26 22:09:21 2012	(r232200)
@@ -38,9 +38,16 @@ static int extract_files(int nfiles, con
 int
 main(void)
 {
-	char *diststring = strdup(getenv("DISTRIBUTIONS"));
+	char *diststring;
 	const char **dists;
 	int i, retval, ndists = 0;
+
+	if (getenv("DISTRIBUTIONS") == NULL) {
+		fprintf(stderr, "DISTRIBUTIONS variable is not set\n");
+		return (1);
+	}
+
+	diststring = strdup(getenv("DISTRIBUTIONS"));
 	for (i = 0; diststring[i] != 0; i++)
 		if (isspace(diststring[i]) && !isspace(diststring[i+1]))
 			ndists++;

Modified: head/usr.sbin/bsdinstall/distfetch/distfetch.c
==============================================================================
--- head/usr.sbin/bsdinstall/distfetch/distfetch.c	Sun Feb 26 21:24:27 2012	(r232199)
+++ head/usr.sbin/bsdinstall/distfetch/distfetch.c	Sun Feb 26 22:09:21 2012	(r232200)
@@ -37,9 +37,16 @@ static int fetch_files(int nfiles, char 
 int
 main(void)
 {
-	char *diststring = strdup(getenv("DISTRIBUTIONS"));
+	char *diststring;
 	char **urls;
 	int i, nfetched, ndists = 0;
+
+	if (getenv("DISTRIBUTIONS") == NULL) {
+		fprintf(stderr, "DISTRIBUTIONS variable is not set\n");
+		return (1);
+	}
+
+	diststring = strdup(getenv("DISTRIBUTIONS"));
 	for (i = 0; diststring[i] != 0; i++)
 		if (isspace(diststring[i]) && !isspace(diststring[i+1]))
 			ndists++;