Repository navigation
expand: don't panic on a missing parameter name in zsh - #1363
benjaminabbitt wants to merge 1 commit into
Conversation
mvdan
left a comment
There was a problem hiding this comment.
Thanks! The fix looks correct, although the godoc on paramName should be way shorter. We also use more generic table-driven tests in this module, although many like in the expand or interp packages don't currently test various lang variants. I would look at expanding an existing table-driven test rather than adding a new and specific one
The zsh parser accepts an omitted parameter name, as in ${} or ${:-foo}, and
leaves ParamExp.Param nil for these (see "syntax: support missing parameter
expansion names in zsh"). The expander read pe.Param.Value at several sites, so
expanding such a word panicked with a nil pointer dereference; e.g.
expand.Fields on `echo x${}y` crashed in listElems.
Real zsh expands a missing name to the empty string (`echo x${}y` prints "xy"),
so read the name through a paramName helper that returns "" for a nil Param,
matching the nil guards already in the printer and simplifier.
c2ab623 to
aceab37
Compare
|
Thanks for taking a look! Shortened the On the table-driven suggestion: I did go hunting for an existing one to hang this off of, but nothing quite fit. The big Closest existing fit was So I left it as its own test but tried to keep it in the house style — table-driven, parameterized over the variants, If you'd still rather have it merged into one of the existing tables, happy to do that — just let me know. |
Under
LangZshthe parser accepts an omitted parameter name (${},${:-foo}) and leavesParamExp.Paramnil, intended since 87df0f9 ("syntax: support missing parameter expansion names in zsh"). Theexpandpackage still readpe.Param.Valueat several sites, so expanding such a word panics:Real zsh expands a missing name to the empty string (
echo x${}yprintsxy), so I read the name through a smallparamNamehelper that returns""for a nilParam. This matches the nil guards already in the printer and simplifier, added when the same nil crashed--simplifyin #1301.TestZshMissingParamNamecovers the plain and double-quoted forms throughexpand.Fields; both panic before the change and expand toxyafter, andgo test ./...passes.Found by fuzzing a pre-tool hook that parses agent-issued commands in the user's
$SHELLdialect and callsexpand.Fieldson them; on a zsh host any command containing${}crashed it.