Date: Wed, 13 Oct 2010 23:42:48 +0200
From: Jilles Tjoelker <jilles@stack.nl>
To: obrien@freebsd.org, freebsd-current@freebsd.org
Subject: Re: [PATCH] fix shell bug in ${var%pattern} expansion
Message-ID: <20101013214247.GA36354@stack.nl>
In-Reply-To: <20101012021914.GA72371@dragon.NUXI.org>
References: <20101012021914.GA72371@dragon.NUXI.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101013214247.GA36354>
