From fullermd@over-yonder.net  Mon Oct 15 16:25:50 2012
Return-Path: <fullermd@over-yonder.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 1DE87AC1
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Oct 2012 16:25:50 +0000 (UTC)
	(envelope-from fullermd@over-yonder.net)
Received: from thyme.infocus-llc.com (server.infocus-llc.com [206.156.254.44])
	by mx1.freebsd.org (Postfix) with ESMTP id E6E448FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Oct 2012 16:25:49 +0000 (UTC)
Received: from draco.over-yonder.net (c-174-50-4-38.hsd1.ms.comcast.net [174.50.4.38])
	(using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits))
	(No client certificate requested)
	by thyme.infocus-llc.com (Postfix) with ESMTPSA id E65E437B4AC
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Oct 2012 11:20:28 -0500 (CDT)
Received: by draco.over-yonder.net (Postfix, from userid 100)
	id 3XgPyN12HfzWh5; Mon, 15 Oct 2012 11:20:28 -0500 (CDT)
Message-Id: <3XgPyN12HfzWh5@draco.over-yonder.net>
Date: Mon, 15 Oct 2012 11:20:28 -0500 (CDT)
From: Matthew D.Fuller <fullermd@over-yonder.net>
Reply-To: Matthew D.Fuller <fullermd@over-yonder.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Fix portsnap's INDEX building
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         172715
>Category:       bin
>Synopsis:       [PATCH] Fix portsnap's INDEX building
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 15 16:30:01 UTC 2012
>Closed-Date:    Mon Feb 04 00:39:39 UTC 2013
>Last-Modified:  Mon Feb 04 00:39:39 UTC 2013
>Originator:     Matthew D. Fuller
>Release:        FreeBSD 9.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD draco.over-yonder.net 9.0-STABLE FreeBSD 9.0-STABLE #0 r237357: Thu Jun 21 01:21:37 CDT 2012 root@draco.over-yonder.net:/usr/obj/usr/src/sys/DRACO amd64


	
>Description:

In r227483, portsnap.sh was changed to use $IFS in several places rather
than calling out to cut(1) to split things up by '|'.  However, in
several places, this was done around a block by "IFS='|'" prior and
"IFS=" after, which has the result of leaving IFS set to the empty string
after the fact.

This causes an error when extract_indices() is called after some of the
fetch functions (as will happen when you run a `portsnap fetch update`)
that looks like:

  Building new INDEX files... DESCRIBE.7 INDEX-8 not provided by portsnap server; INDEX-7 not being generated.


To properly return to default behavior, IFS needs to be unset, not set to
empty.  Changes tested via 'extract' and 'fetch update'.

>How-To-Repeat:
	
>Fix:


Index: portsnap.sh
===================================================================
--- portsnap.sh	(revision 241541)
+++ portsnap.sh	(working copy)
@@ -587,7 +587,7 @@
 
 # Take a list of ${oldhash}|${newhash} and output a list of needed patches
 fetch_make_patchlist() {
-	IFS='|'
+	local IFS='|'
 	echo "" 1>${QUIETREDIR}
 	grep -vE "^([0-9a-f]{64})\|\1$" |
 		while read X Y; do
@@ -596,7 +596,6 @@
 			echo "${X}|${Y}"
 		done
 	echo "" 1>${QUIETREDIR}
-	IFS=
 }
 
 # Print user-friendly progress statistics
@@ -725,7 +724,7 @@
 		fi
 		rm -f diff OLD NEW ${X}-${Y}.gz ptmp
 	done < patchlist 2>${QUIETREDIR}
-	IFS=
+	unset IFS
 	echo "done."
 
 # Update metadata without patches
@@ -810,7 +809,7 @@
 		fi
 		rm -f diff OLD NEW ${X}-${Y}
 	done < patchlist 2>${QUIETREDIR}
-	IFS=
+	unset IFS
 	echo "done."
 
 # Update ports without patches
@@ -948,6 +947,8 @@
 		return 0;
 	fi
 
+	unset IFS
+
 	extract_metadata
 	extract_indices
 }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Mon Oct 15 16:42:47 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172715 
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Mon Oct 15 16:49:04 UTC 2012 
State-Changed-Why:  
awaiting approval or review prior to commit (no action needed from 
submitter) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172715 

From: <dteske@freebsd.org>
To: <bug-followup@FreeBSD.org>, <fullermd@over-yonder.net>
Cc: Devin Teske <dteske@freebsd.org>
Subject: Re: bin/172715: [PATCH] Fix portsnap&#39;s INDEX building
Date: Mon, 15 Oct 2012 18:16:43 -0700

 ------=_NextPart_000_04CB_01CDAB01.3B88F200
 Content-Type: text/plain; charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 
 eadler asked me to take a look at this.
 
 unset'ing IFS in a non-local context should be avoided as it violates POLA (in
 that a programmer whom relies on $IFS would be surprised to find that after
 calling fetch_update() their previous value of $IFS was unset and no-longer
 available).
 
 Please find attached patch.txt as a replacement to the original patch.txt
 submitted with this PR.
 -- 
 Devin
 
 _____________
 The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
 
 ------=_NextPart_000_04CB_01CDAB01.3B88F200
 Content-Type: text/plain; name="patch.txt"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="patch.txt"
 
 Index: portsnap.sh=0A=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
 --- portsnap.sh	(revision 241599)=0A=
 +++ portsnap.sh	(working copy)=0A=
 @@ -587,7 +587,7 @@ fetch_metadata_sanity() {=0A=
  =0A=
  # Take a list of ${oldhash}|${newhash} and output a list of needed =
 patches=0A=
  fetch_make_patchlist() {=0A=
 -	IFS=3D'|'=0A=
 +	local IFS=3D'|'=0A=
  	echo "" 1>${QUIETREDIR}=0A=
  	grep -vE "^([0-9a-f]{64})\|\1$" |=0A=
  		while read X Y; do=0A=
 @@ -596,7 +596,6 @@ fetch_make_patchlist() {=0A=
  			echo "${X}|${Y}"=0A=
  		done=0A=
  	echo "" 1>${QUIETREDIR}=0A=
 -	IFS=3D=0A=
  }=0A=
  =0A=
  # Print user-friendly progress statistics=0A=
 @@ -711,7 +710,7 @@ fetch_update() {=0A=
  =0A=
  # Attempt to apply metadata patches=0A=
  	echo -n "Applying metadata patches... "=0A=
 -	IFS=3D'|'=0A=
 +	local oldifs=3D"$IFS" IFS=3D'|'=0A=
  	while read X Y; do=0A=
  		if [ ! -f "${X}-${Y}.gz" ]; then continue; fi=0A=
  		gunzip -c < ${X}-${Y}.gz > diff=0A=
 @@ -725,7 +724,7 @@ fetch_update() {=0A=
  		fi=0A=
  		rm -f diff OLD NEW ${X}-${Y}.gz ptmp=0A=
  	done < patchlist 2>${QUIETREDIR}=0A=
 -	IFS=3D=0A=
 +	IFS=3D"$oldifs"=0A=
  	echo "done."=0A=
  =0A=
  # Update metadata without patches=0A=
 @@ -792,7 +791,7 @@ fetch_update() {=0A=
  # Attempt to apply ports patches=0A=
  	PATCHCNT=3D`wc -l patchlist`=0A=
  	echo "Applying patches... "=0A=
 -	IFS=3D'|'=0A=
 +	local oldifs=3D"$IFS" IFS=3D'|'=0A=
  	I=3D0=0A=
  	while read X Y; do=0A=
  		I=3D$(($I + 1))=0A=
 @@ -810,7 +809,7 @@ fetch_update() {=0A=
  		fi=0A=
  		rm -f diff OLD NEW ${X}-${Y}=0A=
  	done < patchlist 2>${QUIETREDIR}=0A=
 -	IFS=3D=0A=
 +	IFS=3D"$oldifs"=0A=
  	echo "done."=0A=
  =0A=
  # Update ports without patches=0A=
 @@ -912,7 +911,7 @@ extract_metadata() {=0A=
  =0A=
  # Do the actual work involved in "extract"=0A=
  extract_run() {=0A=
 -	local IFS=3D'|'=0A=
 +	local oldifs=3D"$IFS" IFS=3D'|'=0A=
  	mkdir -p ${PORTSDIR} || return 1=0A=
  =0A=
  	if !=0A=
 @@ -948,6 +947,8 @@ extract_run() {=0A=
  		return 0;=0A=
  	fi=0A=
  =0A=
 +	IFS=3D"$oldifs"=0A=
 +=0A=
  	extract_metadata=0A=
  	extract_indices=0A=
  }=0A=
 
 ------=_NextPart_000_04CB_01CDAB01.3B88F200--

From: "Matthew D. Fuller" <fullermd@over-yonder.net>
To: dteske@freebsd.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/172715: [PATCH] Fix portsnap&#39;s INDEX building
Date: Tue, 16 Oct 2012 00:27:10 -0500

 > unset'ing IFS in a non-local context should be avoided as it
 > violates POLA (in that a programmer whom relies on $IFS would be
 > surprised to find that after calling fetch_update() their previous
 > value of $IFS was unset and no-longer available).
 > 
 > Please find attached patch.txt as a replacement to the original
 > patch.txt submitted with this PR.
 
 Makes as much sense.  I didn't bother since those are the only places
 in the file that set IFS anyway.
 
 I didn't add the local's most of the places as I didn't check deeper
 down the stack in those places to be sure it wouldn't trip something
 else up (anoyingly hard to test the code).  I don't _think_ it will,
 since nothing else explicitly manipulates it, but I wasn't sure, so I
 left it un-local'd.
 
 
 -- 
 Matthew Fuller     (MF4839)   |  fullermd@over-yonder.net
 Systems/Network Administrator |  http://www.over-yonder.net/~fullermd/
            On the Internet, nobody can hear you scream.
State-Changed-From-To: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Wed Oct 24 12:57:37 UTC 2012 
State-Changed-Why:  
committed in r241999 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172715 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Mon Feb 4 00:39:38 UTC 2013 
State-Changed-Why:  
MFCed/fixed by now or it will never be MFCed 

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