-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Recursive arithmetic evaluation (ble.sh) #648
Comments
This is intentional, and this is the first time I've heard of someone using it on purpose. It relates to the security problem here, which has been documented by the Fedora security team, etc. http://www.oilshell.org/blog/2019/01/18.html#a-story-about-a-30-year-old-security-problem https://www.oilshell.org/release/0.8.pre2/doc/known-differences.html#static-parsing (could be elaborated on maybe) I added a note here that an explicit https://github.com/oilshell/oil/wiki/What-Is-Expected-to-Run-Under-OSH |
Another way to think about it is that this restriction is exactly the one that allowed Oil to find the coding error with
In bash, it's valid if |
Oh, really. Hmm, ble.sh might be one of the highly non-trivial type of Bash scripts such that even small part of the codes is out of scope of Oil...
Actually the security issue of the arithmetic expansion is more specifically related to the shell expansion of the arithmetic subscripts mentioned in #645 . Consider the code
Thank you for the explanation! So Oil only allows the static arithmetic expressions (except for I understand the decision that Oil made. But I think it will be helpful if some of these examples (#644 #645 #646 #648) are explicitly described in Q1. Why #640
|
Q1. Good question, in e.g.
So are you saying that BLE relies on the latter behavior on the LHS? I was thinking the former behavior (a string part of a variable name) would be more common, but I didn't inspect the code to see. In any case |
Q2. I'm not sure why
I'm not sure what bash does to be honest... I was surprised just now testing the behavior of assoc arrays in I think Oil's behavior is "explainable" and consistent but I'm open to more |
OK the reason I'm confused is because in bash 4.4 this doesn't work:
I get
|
Q3. Yes I thought about this but didn't do it... It would be possible to add those checks. It's sort of an internal parsing detail -- we parse the whole word, and then extract parts within Filed #652 for this |
Also Oil the |
OK I misunderstood the meaning of Q2!
in bash uses the variable file instead of the string |
Works in both bash and osh. Related to discussion on #648.
This was the example that was a syntax error. I suggested using See the test case in the commit above -- it passes under osh and bash.
|
Q1
Do you mean this Besides that, ble.sh uses recursive arithmetic evaluations. By recursive arithmetic evaluation, I mean the case $ loop='(i<=100)&&(s+=i,i++,loop)'; let i=0 s=0 loop; echo "$s"
OK, I think that's understandable design. Q2I'm sorry. I should have make it clear what we want to do in these example. I consider the situation that we have some key Maybe I also need to point out the fact that Bash doesn't accept an empty string as a key, which may be one of the factor that confuses you.
This is caused by an empty key (which Bash doesn't allow). The following example should work: $ foo=X; declare -A A=(['$foo']=42); (( c = 1 + A[\$foo] )); echo c=$c
c=1
I cannot remove Q3Thank you! |
Works in both bash and osh. Related to discussion on oils-for-unix#648.
Nothing. The recursive evaluation of arithmetic expressions are different from #640, #645 and #645, but I think you can just describe the recursive evaluation of arithmetic expressions in known-differences.html unless you consider missing recursive evaluation is trivial. (Note: this recursive nature is documented in Bash manual 6.5 "The value of a variable is evaluated as an arithmetic expression when it is referenced"). You can close the issue now. Thank you. |
@akinomyoga I implemented Working on |
In Bash, arithmetic evaluation is performed recursively when the variable is referenced in the arithmetic expressions. The script ble.sh uses this behavior in some part. Oil seems not to support this.
Maybe the above use case is not popular for light users, but I think the following case is what many users can fall into, which is related to either the expansion order or the recursive evaluation:
The text was updated successfully, but these errors were encountered: