c++ - Defending against stack overflow by user scripts -
c++ - Defending against stack overflow by user scripts -
c++ has limited stack space no way functions check whether there's plenty space left them run. don't know when writing script bindings.
for example:
class container : widget { void addchild(widgetptr child) { ... } void draw(canvas& canvas) { (auto kid : m_children) { child.draw(); } } };
a malicious script can crash program:
var = new container() (i = 0; < 10000000; i++) { var b = new container() a.addchild(b) = b } a.draw() // 10000000 nested calls ---> stack overflow
there's callback problem:
void dosomething(std::function<void()> callback) { callback(); }
if wrapped using this:
scriptvalue dosomething_wrapper(scriptargs args) { dosomething([&]() { args[0].callasfunction(); }); }
crashed using:
function badcallback() { dosomething(badcallback) } dosomething(badcallback) ... dosomething_wrapper dosomething scriptvalue::callasfunction ... dosomething_wrapper dosomething scriptvalue::callasfunction ... boom!
what's idiomatic way defend against to the lowest degree inconvenience?
what browsers written in c++ (firefox, chrome) do?
what can not introduce vulnerability accident?
while "malicious" script cause stack overflow, describe, can´t harm programme more causing crashes way (at to the lowest degree on modern os stack limit checked , hence it´s safe against overwrites of other of import data).
if it´s critical programme running time, process has monitor (and restart if necessary. not because stack overflows, there many more potential problems.). other that, there isn´t much 1 can if os stack used. dynamically allocating big memory block single pointer in stack , doing whole memory management manually in block possible, maybe impractical.
about eg. firefox: @ to the lowest degree parts of programme using own memory management (but i´m not sure if relevant plugins, scripts etc.). additionally, there separate process plugin-container.exe
(at to the lowest degree on windows), , killing won´t kill firefox (only plugin part flash etc. won´t work anymore , user gets message plugin crashing).
c++ security scripting stack-overflow
Comments
Post a Comment