From f1dfe106f9ba3a02a44a342c028fa2502063ad52 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 6 Apr 2020 20:10:12 +0000 Subject: [PATCH] Fix bug introduced in rev 1.142 with the additional/optional arguments to the yesno() and noyes() methods: We need to check the argument count before using the second (optional) argument or else it has some garbage/left-over value from some previous JS function call. And no, just increasing the argument count in the method table isn't enough. :-( Reported by echicken and DaiTengu, thanks! --- src/sbbs3/js_console.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sbbs3/js_console.cpp b/src/sbbs3/js_console.cpp index fda1a3330d..6f5343daf6 100644 --- a/src/sbbs3/js_console.cpp +++ b/src/sbbs3/js_console.cpp @@ -859,7 +859,7 @@ js_yesno(JSContext *cx, uintN argc, jsval *arglist) JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL); if(cstr==NULL) return JS_FALSE; - if(JSVAL_IS_NUMBER(argv[1])) { + if(argc > 1 && JSVAL_IS_NUMBER(argv[1])) { if(!JS_ValueToInt32(cx, argv[1], &mode)) return JS_FALSE; } @@ -891,7 +891,7 @@ js_noyes(JSContext *cx, uintN argc, jsval *arglist) JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL); if(cstr==NULL) return JS_FALSE; - if(JSVAL_IS_NUMBER(argv[1])) { + if(argc > 1 && JSVAL_IS_NUMBER(argv[1])) { if(!JS_ValueToInt32(cx, argv[1], &mode)) return JS_FALSE; } @@ -1985,11 +1985,11 @@ static jsSyncMethodSpec js_console_functions[] = { ,JSDOCSTR("put one or more characters in the keyboard input buffer") ,310 }, - {"yesno", js_yesno, 1, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]") + {"yesno", js_yesno, 2, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]") ,JSDOCSTR("YES/no question - returns <i>true</i> if 'yes' is selected") ,310 }, - {"noyes", js_noyes, 1, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]") + {"noyes", js_noyes, 2, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]") ,JSDOCSTR("NO/yes question - returns <i>true</i> if 'no' is selected") ,310 }, -- GitLab