From owner-freebsd-current@FreeBSD.ORG Wed Oct 13 21:42:50 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D1941065697; Wed, 13 Oct 2010 21:42:50 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 045CC8FC2C; Wed, 13 Oct 2010 21:42:50 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 425331DD67F; Wed, 13 Oct 2010 23:42:48 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 2B45017312; Wed, 13 Oct 2010 23:42:48 +0200 (CEST) Date: Wed, 13 Oct 2010 23:42:48 +0200 From: Jilles Tjoelker To: obrien@freebsd.org, freebsd-current@freebsd.org Message-ID: <20101013214247.GA36354@stack.nl> References: <20101012021914.GA72371@dragon.NUXI.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101012021914.GA72371@dragon.NUXI.org> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Subject: Re: [PATCH] fix shell bug in ${var%pattern} expansion X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2010 21:42:50 -0000 On Mon, Oct 11, 2010 at 07:19:14PM -0700, David O'Brien wrote: > At $WORK we hit a bug where ${var%/*} was not producing the correct > expansion. There are two patches to fix this. I prefer the first > as I feel it is cleaner from an API perspective. I've also added > a regression testcase that shows the problem. > Thoughts? Thank you, I think this is the mysterious bug I encountered a while ago while making changes to arithmetic expansion, heavily using the stack string. It only failed when /etc/rc.d/nfsserver was called from /etc/rc on boot. Your patch looks good (the first one) and works for me. The second patch indeed seems a hack rather than fixing the problem properly. Style bug: > +growstrstackblock(int n) { The opening brace should be on its own line. Your test is too fragile: it often fails to detect the bug. Calling like sh -c '. expansion/trim4.0' gives the correct output even with a buggy sh. I propose something like this, or perhaps with an additional string comparison: # $FreeBSD$ v1=/homes/SOME_USER v2= v3=C123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 while [ ${#v2} -lt 2000 ]; do v4="${v2} ${v1%/*} $v3" if [ ${#v4} -ne $((${#v2} + ${#v3} + 8)) ]; then echo bad: ${#v4} -ne $((${#v2} + ${#v3} + 8)) fi v2=x$v2 v3=y$v3 done -- Jilles Tjoelker