-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
Add support for require method in lua #23354
Conversation
44a8a7d
to
cbd3420
Compare
@bugobliterator can you add an example script using require, with an examples/modules/ script? |
ebf099d
to
c5b4930
Compare
@bugobliterator I tested with an aerobatics schedule, and min heap needed in SITL went from 270000 to 276000, which is a bit more than I expected. |
I'm not sure if this does everything desired correctly. I'd need to check, but sharing global tables means you break the sandbox and one script that overrides something can take out the other scripts global access to something. |
Ok, I see the vulnerability, to illustrate @WickedShell 's point here's an example:
if we are to run above script with my change, the result is going to be foloowing:
Which breaks the sandbox, as pointed out by @WickedShell . whereas before it was:
Also to point out this vulnerability is not for generated bindings where methods are hidden behind closures, out of reach from global modification. Another thing to know, sandbox has already been broken through some of the |
4c5c7c0
to
0a08938
Compare
@WickedShell @tridge @IamPete1 I have updated the require library to follow the sandboxing rules. Now when you require a module, the underlying script inherits the _ENV from caller script. |
0a08938
to
9be23d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had a play about, loading some pre-existing lua libraries ect. All seems to work as expected. Library's get full set of methods built in and custom.
It all seems to work, it would be nice to find another way to do get the environment and remove the lua_get_current_ref
stuff. But ultimately this works and I'm not sure of any other way. We can always rework if we find such a way in the future.
I'd like to retest memory/cpu impact for aerobatics |
9be23d8
to
073a12f
Compare
80056c5
to
2856b68
Compare
@andypnz we need to test this with aerobatics in one of our Thursday sessions |
Let’s do that :-) Shall we start up again tomorrow, or Thursday next week? |
@bugobliterator tested with aerobatics on top of this branch and it uses slightly less memory! About 1k less heap needed with this PR than without (275k vs 276k) |
Hello @bugobliterator, Is support for the Lua require limited to Lua scripts embedded in the firmware? Or Is support for the Lua require expected to work with scripts upload to an SD card? |
Should work for both and combinations. ROMFS was broken for a while but should work now (#26157) |
Thank you for the response Peter. Prior to my earlier post I had attempted with scripting running on simulation copter. However, it was failing as not finding the referenced Lua script. After reading your response, I went back and tried it again, and realized that I needed to include the scripts path (even though I thought I had tried that earlier):
In summary, it is working for me. Again, thank you for the response. |
Also move the global library initialisation out of sandbox method. This way we initialise the lua libs once and then set the reference inside the sandbox, this is similar to what we do with our generated lua bindings.
Split from following PR as requested:
#13660
Current master
With package module loaded