Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax check of dynamic rvalue names in arithmetic expressions (ble.sh) #644

Closed
akinomyoga opened this issue Mar 9, 2020 · 2 comments
Closed

Comments

@akinomyoga
Copy link
Collaborator

In Issue #620

I added some failing test cases for dynamic assignment here inspired by ble.sh:

While testing ble.sh, I noticed that Oil does not produce syntax errors for ((${prefix}var)), but it actually fails to evaluate at runtime. (Or does this construct ((${prefix}var)) have a different usage in Oil?) The added test cases 8fdb25d do not contain this kind of the case where the dynamic variables are referenced as rvalue.

$ bin/osh -n -c 'echo $((${prefix}var))'
(C {<echo>}
  {
    (word_part.ArithSub
      anode: (arith_expr.ArithWord w:{(${ Id.VSub_Name prefix) <Id.Lit_ArithVarLike var>})
    )
  }
)
$ bin/osh -c 'ble_var=123; prefix=ble_; echo $((${prefix}var))'
  ble_var=123; prefix=ble_; echo $((${prefix}var))
                                    ^~
[ -c flag ]:1: warning: Invalid integer constant 'ble_var'
0
$
@andychu
Copy link
Contributor

andychu commented Mar 9, 2020

Yes this is intentional, same issue as #648 and #645. Arithmetic is never recursively evaluated, both because it's confusing and because of the security issue.

This is sort of philosophically related, and has the Fedora security links at the end too:

http://www.oilshell.org/release/latest/doc/simple-word-eval.html

@andychu
Copy link
Contributor

andychu commented Mar 9, 2020

Let's talk about them all on #648 if you like

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

No branches or pull requests

2 participants