Re: [PATCH] fix shell bug in ${var%pattern} expansion

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jilles Tjoelker
Date: Wednesday, October 13, 2010 - 2:42 pm

On Mon, Oct 11, 2010 at 07:19:14PM -0700, David O'Brien wrote:


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:
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
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] fix shell bug in ${var%pattern} expansion, David O'Brien, (Mon Oct 11, 7:19 pm)
Re: [PATCH] fix shell bug in ${var%pattern} expansion, Jilles Tjoelker, (Wed Oct 13, 2:42 pm)
Re: [PATCH] fix shell bug in ${var%pattern} expansion, David O'Brien, (Wed Oct 13, 4:24 pm)