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

Tick rate control #45

Open
matiasah opened this issue Aug 8, 2014 · 7 comments
Open

Tick rate control #45

matiasah opened this issue Aug 8, 2014 · 7 comments

Comments

@matiasah
Copy link

matiasah commented Aug 8, 2014

In Lua 5.1 we were able to limit the tick rate with the debug library, but it hasn't been implemented on UniLua. Can you at least implement some functions to control the tick rate/infinite loops/stack overflow?

@xebecnan
Copy link
Owner

Could you describe how this can be done in lua 5.1 for reference?

@matiasah
Copy link
Author

Right now I'm on phone, so I'll get you the quickest answer. Once I go to my computer I'll repost an implemented answer.

debug.sethook(function, "", quota)
Quota is every how many operations Lua will trigger the function from the first argument. If you want, you can add an error to the function from the first argument and the execution will stop. I'm not sure about the second parameter because I haven't used used this function for more things, but as I said, I'll repost an implemented answer.

@matiasah
Copy link
Author

Also: if you put set the quota to 1000 and in Lua code you do the following.
for i =1, 2000 do
end

The function should be called, and if it triggers an error, the execution should stop on i = 1000

@xebecnan
Copy link
Owner

Thanks, I got it. It's the sethook function in debug library.
I'll work on it later.

@matiasah
Copy link
Author

probably it will be pointless if I repost it now, because you seem to have got it. But I'll do it anyway.
I used this code:
debug.sethook(function () error("tick quota exceeded") end, "", 5000)
for i = 1, 10000 do
print(i)
end
It prints from 1 to 1249, and after 1249 it breaks with the error "tick quota exceeded"

@matiasah
Copy link
Author

Hey, after I did some more tests with the debug library I noticed that the "l" mode does not detect infinite loops. This is quite essential to execute untrusted code in the server environment. When you start making this function, could you add another mode like "a" that would detect any kind of loops (from the "l" mode) and incluiding while and repeat-loops (the undetectable ones)?

@matiasah
Copy link
Author

Hey, it's been about two or three months. So I'm just wondering if you can do it or not, how much more time would that take? The only purpose I have on this is to run untrustable code with UniLua so I could stop people from doing infinite loops that crashes the VM.

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