Skip to content

check argv length before indexing (fixes #2411)#2442

Merged
andychu merged 2 commits intosoil-stagingfrom
melvinw/fix-2411
Oct 4, 2025
Merged

check argv length before indexing (fixes #2411)#2442
andychu merged 2 commits intosoil-stagingfrom
melvinw/fix-2411

Conversation

@melvinw
Copy link
Collaborator

@melvinw melvinw commented Sep 29, 2025

We have a helper to check if prefix bindings should pe preserved when running a simple command. This check requires checking the first argument of the command line, but doesn't check the length before indexing. This commit patches the helper to return early if argv is empty. From there, the usual command execution logic will take care of the rest: either a noop, or erroring out if strict_argv is enabled.

We have a helper to check if prefix bindings should pe preserved when
running a simple command. This check requires checking the first
argument of the command line, but doesn't check the length before
indexing. This commit patches the helper to return early if argv is
empty. From there, the usual command execution logic will take care of
the rest: either a noop, or erroring out if strict_argv is enabled.
Copy link
Contributor

@andychu andychu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm glad this was a localized fix!

elif case(cmd_value_e.Argv):
cmd_val = cast(cmd_value.Argv, UP_cmd_val)
if len(cmd_val.argv) == 0:
return True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm it's somewhat surprising to me that the binding persists - I was thinking it should be return False !!!

$ bash -c 'FOO=bar $undef; echo FOO=$FOO'
FOO=bar


$ bash -c 'FOO=bar echo; echo FOO=$FOO'  # does NOT persist
FOO=

I would have thought FOO=bar goes out of scope in the first case, like the second

It looks like the spec test covers it, but how about adding a comment about this behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@andychu andychu merged commit 5fff771 into soil-staging Oct 4, 2025
19 checks passed
@andychu
Copy link
Contributor

andychu commented Oct 4, 2025

Great thanks!

@melvinw melvinw deleted the melvinw/fix-2411 branch October 4, 2025 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants