Skip to content
Snippets Groups Projects
Commit cb5188bd authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix JS global object corruption when invoking JS global hotkey handlers

As reported by Ragnarok and The Lizard Master, invoking a JS global
hot-key handler (e.g. hitting Ctrl-U or Ctrl-P with the privatemsg
or nodelist modules installed as handlers) would lead to the global
object being cleared/corrupted so other scripts would then fail to
run correctly (e.g. Error: can't open sbbsdefs.js: No such file or directory)

This probably explains the JS_GC/JS_ENDREQUEST change needed when
the hotkey-specific JS runtime/context/scope was introduced last year.
Should revisit that too.
parent 34909899
No related branches found
No related tags found
No related merge requests found
Pipeline #28 passed
...@@ -563,7 +563,7 @@ js_OperationCallback(JSContext *cx) ...@@ -563,7 +563,7 @@ js_OperationCallback(JSContext *cx)
return ret; return ret;
} }
long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scope, JSContext* js_cx) long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scope, JSContext* js_cx, JSObject* js_glob)
{ {
char* p; char* p;
char* args=NULL; char* args=NULL;
...@@ -580,6 +580,8 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco ...@@ -580,6 +580,8 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
if(js_cx == NULL) if(js_cx == NULL)
js_cx = this->js_cx; js_cx = this->js_cx;
if(js_glob == NULL)
js_glob = this->js_glob;
if(js_cx==NULL) { if(js_cx==NULL) {
errormsg(WHERE,ERR_CHK,"JavaScript support",0); errormsg(WHERE,ERR_CHK,"JavaScript support",0);
......
...@@ -195,7 +195,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) ...@@ -195,7 +195,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
js_hotkey_cx = js_init(&js_hotkey_runtime, &js_hotkey_glob, "HotKey"); js_hotkey_cx = js_init(&js_hotkey_runtime, &js_hotkey_glob, "HotKey");
js_create_user_objects(js_hotkey_cx, js_hotkey_glob); js_create_user_objects(js_hotkey_cx, js_hotkey_glob);
} }
js_execfile(cmdstr(cfg.hotkey[i]->cmd+1,nulstr,nulstr,tmp), /* startup_dir: */NULL, /* scope: */js_hotkey_glob, js_hotkey_cx); js_execfile(cmdstr(cfg.hotkey[i]->cmd+1,nulstr,nulstr,tmp), /* startup_dir: */NULL, /* scope: */js_hotkey_glob, js_hotkey_cx, js_hotkey_glob);
} else } else
external(cmdstr(cfg.hotkey[i]->cmd,nulstr,nulstr,tmp),0); external(cmdstr(cfg.hotkey[i]->cmd,nulstr,nulstr,tmp),0);
if(!(sys_status&SS_SPLITP)) { if(!(sys_status&SS_SPLITP)) {
......
...@@ -406,7 +406,7 @@ public: ...@@ -406,7 +406,7 @@ public:
JSContext* js_hotkey_cx; JSContext* js_hotkey_cx;
JSObject* js_hotkey_glob; JSObject* js_hotkey_glob;
js_callback_t js_callback; js_callback_t js_callback;
long js_execfile(const char *fname, const char* startup_dir, JSObject* scope = NULL, JSContext* cx = NULL); long js_execfile(const char *fname, const char* startup_dir, JSObject* scope = NULL, JSContext* cx = NULL, JSObject* glob = NULL);
long js_execmodule(const char *fname, long mode, const char* startup_dir); long js_execmodule(const char *fname, long mode, const char* startup_dir);
JSContext* js_init(JSRuntime**, JSObject**, const char* desc); JSContext* js_init(JSRuntime**, JSObject**, const char* desc);
void js_cleanup(void); void js_cleanup(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment