Commit d9917cae authored by deuce's avatar deuce
Browse files

*_TO_STRING() considered harmful.

parent a0904ba5
......@@ -208,10 +208,11 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
break;
case CON_PROP_ATTR:
if(JSVAL_IS_STRING(*vp)) {
JSVALUE_TO_STRING(cx, *vp, sval, NULL);
JSVALUE_TO_MSTRING(cx, *vp, sval, NULL);
if(sval==NULL)
break;
val=attrstr(sval);
free(sval);
}
rc=JS_SUSPENDREQUEST(cx);
sbbs->attr(val);
......@@ -230,10 +231,11 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
sbbs->autoterm=val;
break;
case CON_PROP_TERMINAL:
JSVALUE_TO_STRING(cx, *vp, sval, NULL);
JSVALUE_TO_MSTRING(cx, *vp, sval, NULL);
if(sval==NULL)
break;
SAFECOPY(sbbs->terminal,sval);
free(sval);
break;
case CON_PROP_INACTIV_WARN:
sbbs->cfg.sec_warn = (uint16_t)val;
......@@ -264,10 +266,11 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
sbbs->getstr_offset=val;
break;
case CON_PROP_QUESTION:
JSVALUE_TO_STRING(cx, *vp, sval, NULL);
JSVALUE_TO_MSTRING(cx, *vp, sval, NULL);
if(sval==NULL)
break;
SAFECOPY(sbbs->question,sval);
free(sval);
break;
case CON_PROP_CTRLKEY_PASSTHRU:
if(JSVAL_IS_STRING(*vp)) {
......@@ -275,8 +278,11 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
if((str=JS_ValueToString(cx, *vp))==NULL)
break;
JSSTRING_TO_STRING(cx, str, s, NULL);
JSSTRING_TO_MSTRING(cx, str, s, NULL);
if(s==NULL)
break;
val=str_to_bits(sbbs->cfg.ctrlkey_passthru, s);
free(s);
}
sbbs->cfg.ctrlkey_passthru=val;
break;
......@@ -448,7 +454,7 @@ js_handle_ctrlkey(JSContext *cx, uintN argc, jsval *arglist)
if(JSVAL_IS_INT(argv[0]))
key=(char)JSVAL_TO_INT(argv[0]);
else {
JSVALUE_TO_STRING(cx, argv[0], keystr, NULL);
JSVALUE_TO_ASTRING(cx, argv[0], keystr, 2, NULL);
if(keystr==NULL)
return(JS_FALSE);
key=keystr[0];
......@@ -507,8 +513,11 @@ js_getstr(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
if(js_str!=NULL) {
JSSTRING_TO_STRING(cx, js_str, p2, NULL);
JSSTRING_TO_MSTRING(cx, js_str, p2, NULL);
if(p2==NULL)
return JS_FALSE;
sprintf(p,"%.*s",(int)maxlen,p2);
free(p2);
}
rc=JS_SUSPENDREQUEST(cx);
......@@ -586,9 +595,12 @@ js_getkeys(JSContext *cx, uintN argc, jsval *arglist)
if(js_str==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
val=sbbs->getkeys(cstr,maxnum);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
if(val==-1) { // abort
......@@ -643,13 +655,15 @@ js_gettemplate(JSContext *cx, uintN argc, jsval *arglist)
if(js_str==NULL)
str[0]=0;
else {
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
SAFECOPY(str,cstr);
JSSTRING_TO_STRBUF(cx, js_str, str, sizeof(str), NULL);
}
JSSTRING_TO_STRING(cx, js_fmt, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_fmt, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->gettmplt(str,cstr,mode);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
if((js_str=JS_NewStringCopyZ(cx, str))==NULL)
......@@ -664,6 +678,7 @@ js_ungetstr(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
char* p;
char* op;
sbbs_t* sbbs;
JSString* js_str;
jsrefcount rc;
......@@ -676,11 +691,15 @@ js_ungetstr(JSContext *cx, uintN argc, jsval *arglist)
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, js_str, p, NULL);
JSSTRING_TO_MSTRING(cx, js_str, op, NULL);
if(op==NULL)
return JS_FALSE;
p=op;
rc=JS_SUSPENDREQUEST(cx);
while(p && *p)
sbbs->ungetkey(*(p++));
free(op);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -702,9 +721,12 @@ js_yesno(JSContext *cx, uintN argc, jsval *arglist)
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->yesno(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -726,9 +748,12 @@ js_noyes(JSContext *cx, uintN argc, jsval *arglist)
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->noyes(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -750,9 +775,12 @@ js_mnemonics(JSContext *cx, uintN argc, jsval *arglist)
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->mnemonics(cstr);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -765,8 +793,11 @@ js_set_attr(JSContext* cx, sbbs_t* sbbs, jsval val)
jsrefcount rc;
if(JSVAL_IS_STRING(val)) {
JSVALUE_TO_STRING(cx, val, as, NULL);
JSVALUE_TO_MSTRING(cx, val, as, NULL);
if(as==NULL)
return JS_FALSE;
attr=attrstr(as);
free(as);
}
else {
if(!JS_ValueToInt32(cx, val, &attr))
......@@ -925,7 +956,8 @@ js_print(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
sbbs_t* sbbs;
char* cstr;
char* cstr=NULL;
size_t cstr_sz;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -934,13 +966,15 @@ js_print(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
for (i = 0; i < argc; i++) {
JSVALUE_TO_STRING(cx, argv[i], cstr, NULL);
JSVALUE_TO_RASTRING(cx, argv[i], cstr, &cstr_sz, NULL);
if(cstr==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
sbbs->bputs(cstr);
JS_RESUMEREQUEST(cx, rc);
}
if(cstr)
free(cstr);
return(JS_TRUE);
}
......@@ -958,9 +992,12 @@ js_strlen(JSContext *cx, uintN argc, jsval *arglist)
if((str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(bstrlen(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -971,7 +1008,8 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
sbbs_t* sbbs;
uintN i;
char* str;
char* str=NULL;
size_t str_sz;
size_t len;
jsrefcount rc;
......@@ -981,13 +1019,14 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
for (i = 0; i < argc; i++) {
JSVALUE_TO_STRING(cx, argv[i], str, &len);
JSVALUE_TO_RASTRING(cx, argv[i], str, &str_sz, &len);
if(str==NULL)
return(JS_FALSE);
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->rputs(str, len);
JS_RESUMEREQUEST(cx, rc);
}
free(str);
return(JS_TRUE);
}
......@@ -1034,9 +1073,12 @@ js_putmsg(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->putmsg(cstr,mode);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1065,9 +1107,12 @@ js_printfile(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->printfile(cstr,mode);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1109,9 +1154,12 @@ js_printtail(JSContext *cx, uintN argc, jsval *arglist)
if(!lines)
lines=5;
JSSTRING_TO_STRING(cx, js_str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->printtail(cstr,lines,mode);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1133,9 +1181,12 @@ js_editfile(JSContext *cx, uintN argc, jsval *arglist)
if((str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->editfile(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1174,18 +1225,36 @@ js_uselect(JSContext *cx, uintN argc, jsval *arglist)
if((js_str=JS_ValueToString(cx, argv[i]))==NULL)
return(JS_FALSE);
if(title==NULL)
JSSTRING_TO_STRING(cx, js_str, title, NULL) // Magicsemicolon
else if(item==NULL)
JSSTRING_TO_STRING(cx, js_str, item, NULL) // Magicsemicolon
else {
JSSTRING_TO_STRING(cx, js_str, ar_str, NULL);
if(title==NULL) {
JSSTRING_TO_MSTRING(cx, js_str, title, NULL) // Magicsemicolon
if(title==NULL)
return JS_FALSE;
}
else if(item==NULL) {
JSSTRING_TO_MSTRING(cx, js_str, item, NULL) // Magicsemicolon
if(item==NULL) {
free(title);
return JS_FALSE;
}
}
else if(ar_str==NULL) {
JSSTRING_TO_MSTRING(cx, js_str, ar_str, NULL);
if(ar_str==NULL) {
free(item);
free(title);
return JS_FALSE;
}
ar=arstr(NULL,ar_str,&sbbs->cfg);
free(ar_str);
}
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->uselect(1, num, title, item, ar)));
if(title)
free(title);
if(item)
free(item);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1208,9 +1277,12 @@ js_center(JSContext *cx, uintN argc, jsval *arglist)
if (!str)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->center(cstr);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1846,16 +1918,22 @@ static jsSyncMethodSpec js_console_functions[] = {
static JSBool js_console_resolve(JSContext *cx, JSObject *obj, jsid id)
{
char* name=NULL;
JSBool ret;
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval))
JSSTRING_TO_STRING(cx, JSVAL_TO_STRING(idval), name, NULL);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx);
}
}
return(js_SyncResolve(cx, obj, name, js_console_properties, js_console_functions, NULL, 0));
ret=js_SyncResolve(cx, obj, name, js_console_properties, js_console_functions, NULL, 0);
if(name)
free(name);
return ret;
}
static JSBool js_console_enumerate(JSContext *cx, JSObject *obj)
......
......@@ -650,7 +650,8 @@ js_log(JSContext *cx, uintN argc, jsval *arglist)
JSString* str=NULL;
sbbs_t* sbbs;
jsrefcount rc;
char *line;
char *line=NULL;
size_t line_sz=0;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -665,7 +666,7 @@ js_log(JSContext *cx, uintN argc, jsval *arglist)
for(; i<argc; i++) {
if((str=JS_ValueToString(cx, argv[i]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, line, NULL);
JSSTRING_TO_RASTRING(cx, str, line, &line_sz, NULL);
if(line==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
......@@ -677,6 +678,7 @@ js_log(JSContext *cx, uintN argc, jsval *arglist)
lprintf(level,"Node %d %s", sbbs->cfg.node_num, line);
JS_RESUMEREQUEST(cx, rc);
}
free(line);
if(str==NULL)
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -760,6 +762,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
sbbs_t* sbbs;
jsrefcount rc;
char *cstr;
size_t cstr_sz;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -769,7 +772,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
for (i = 0; i < argc; i++) {
if((str=JS_ValueToString(cx, argv[i]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, cstr, NULL);
JSSTRING_TO_RASTRING(cx, str, cstr, &cstr_sz, NULL);
if(cstr==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
......@@ -792,7 +795,8 @@ js_write_raw(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
char* str=NULL;
char* str=NULL;
size_t str_sz=0;
size_t len;
sbbs_t* sbbs;
jsrefcount rc;
......@@ -803,7 +807,7 @@ js_write_raw(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
for (i = 0; i < argc; i++) {
JSVALUE_TO_STRING(cx, argv[i], str, &len);
JSVALUE_TO_RASTRING(cx, argv[i], str, &str_sz, &len);
if(str==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
......@@ -879,13 +883,14 @@ js_alert(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
JSVALUE_TO_STRING(cx, argv[0], cstr, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], cstr, NULL);
if(cstr==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
sbbs->attr(sbbs->cfg.color[clr_err]);
sbbs->bputs(cstr);
free(cstr);
sbbs->attr(LIGHTGRAY);
sbbs->bputs(crlf);
JS_RESUMEREQUEST(cx, rc);
......@@ -908,12 +913,13 @@ js_confirm(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
JSVALUE_TO_STRING(cx, argv[0], cstr, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], cstr, NULL);
if(cstr==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->yesno(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -931,12 +937,13 @@ js_deny(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
JSVALUE_TO_STRING(cx, argv[0], cstr, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], cstr, NULL);
if(cstr==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->noyes(cstr)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -958,20 +965,18 @@ js_prompt(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
JSVALUE_TO_STRING(cx, argv[0], prompt, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], prompt, NULL);
if(prompt==NULL)
return(JS_FALSE);
if(argc>1) {
JSVALUE_TO_STRING(cx, argv[1], cstr, NULL);
if(cstr==NULL)
return(JS_FALSE);
SAFECOPY(instr,cstr);
JSVALUE_TO_STRBUF(cx, argv[1], instr, sizeof(instr), NULL);
} else
instr[0]=0;
rc=JS_SUSPENDREQUEST(cx);
sbbs->bprintf("\1n\1y\1h%s\1w: ",prompt);
free(prompt);
if(!sbbs->getstr(instr,sizeof(instr)-1,K_EDIT)) {
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment