Commit 9a9dd70c authored by deuce's avatar deuce
Browse files

Remove use of stack-clobbering *_TO_STRING() macros.

parent fcea4a6e
......@@ -641,12 +641,27 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
}
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
JSVALUE_TO_STRING(cx, argv[1], key, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
JSVALUE_TO_MSTRING(cx, argv[1], key, NULL);
HANDLE_PENDING(cx);
/*
* Although section can be NULL (ie: root), a NULL key will cause a
* segfault.
*/
if(key==NULL) {
JS_ReportError(cx, "Invalid NULL key specified");
if(section)
free(section);
return JS_FALSE;
}
if(argc < 3 || dflt==JSVAL_VOID) { /* unspecified default value */
rc=JS_SUSPENDREQUEST(cx);
cstr=iniReadString(p->fp,section,key,NULL,buf);
if(section)
free(section);
if(key)
free(key);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, get_value(cx, cstr));
return(JS_TRUE);
......@@ -695,8 +710,13 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist,DOUBLE_TO_JSVAL(dbl));
}
else if(JSVAL_IS_NUMBER(dflt)) {
if(!JS_ValueToInt32(cx,dflt,&i))
if(!JS_ValueToInt32(cx,dflt,&i)) {
if(section)
free(section);
if(key)
free(key);
return(JS_FALSE);
}
rc=JS_SUSPENDREQUEST(cx);
i=iniReadInteger(p->fp,section,key,i);
JS_RESUMEREQUEST(cx, rc);
......@@ -711,6 +731,10 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cstr2)));
}
if(section)
free(section);
if(key)
free(key);
return(JS_TRUE);
}
......@@ -719,7 +743,7 @@ static JSBool
js_iniSetValue_internal(JSContext *cx, JSObject *obj, uintN argc, jsval* argv, jsval *rval)
{
char* section=ROOT_SECTION;
char* key;
char* key=NULL;
char* result=NULL;
int32 i;
jsval value=argv[2];
......@@ -741,13 +765,18 @@ js_iniSetValue_internal(JSContext *cx, JSObject *obj, uintN argc, jsval* argv, j
return(JS_TRUE);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
JSVALUE_TO_STRING(cx, argv[1], key, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
JSVALUE_TO_MSTRING(cx, argv[1], key, NULL);
HANDLE_PENDING(cx);
rc=JS_SUSPENDREQUEST(cx);
if((list=iniReadFile(p->fp))==NULL) {
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
if(section)
free(section);
if(key)
free(key);
return JS_TRUE;
}
JS_RESUMEREQUEST(cx, rc);
......@@ -763,8 +792,13 @@ js_iniSetValue_internal(JSContext *cx, JSObject *obj, uintN argc, jsval* argv, j
result = iniSetFloat(&list,section,key,JSVAL_TO_DOUBLE(value),NULL);
}
else if(JSVAL_IS_NUMBER(value)) {
if(!JS_ValueToInt32(cx,value,&i))
return(JS_FALSE);
if(!JS_ValueToInt32(cx,value,&i)) {
if(section)
free(section);
if(key)
free(key);
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
result = iniSetInteger(&list,section,key,i,NULL);
JS_RESUMEREQUEST(cx, rc);
......@@ -814,7 +848,7 @@ js_iniRemoveKey(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* section=ROOT_SECTION;
char* key;
char* key=NULL;
private_t* p;
str_list_t list;
jsrefcount rc;
......@@ -830,17 +864,30 @@ js_iniRemoveKey(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
JSVALUE_TO_STRING(cx, argv[1], key, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
JSVALUE_TO_MSTRING(cx, argv[1], key, NULL);
HANDLE_PENDING(cx);
if(key==NULL) {
JS_ReportError(cx, "Invalid NULL key specified");
if(section)
free(section);
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
if((list=iniReadFile(p->fp))==NULL) {
JS_RESUMEREQUEST(cx, rc);
if(section)
free(section);
free(key);
return(JS_TRUE);
}
if(iniRemoveKey(&list,section,key))
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list)));
if(section)
free(section);
free(key);
strListFree(&list);
JS_RESUMEREQUEST(cx, rc);
......@@ -868,18 +915,24 @@ js_iniRemoveSection(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL) {
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
HANDLE_PENDING(cx);
}
rc=JS_SUSPENDREQUEST(cx);
if((list=iniReadFile(p->fp))==NULL) {
JS_RESUMEREQUEST(cx, rc);
if(section)
free(section);
return(JS_TRUE);
}
if(iniRemoveSection(&list,section))
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list)));
if(section)
free(section);
strListFree(&list);
JS_RESUMEREQUEST(cx, rc);
......@@ -910,13 +963,17 @@ js_iniGetSections(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc)
JSVALUE_TO_STRING(cx, argv[0], prefix, NULL);
if(argc) {
JSVALUE_TO_MSTRING(cx, argv[0], prefix, NULL);
HANDLE_PENDING(cx);
}
array = JS_NewArrayObject(cx, 0, NULL);
rc=JS_SUSPENDREQUEST(cx);
list = iniReadSectionList(p->fp,prefix);
if(prefix)
free(prefix);
JS_RESUMEREQUEST(cx, rc);
for(i=0;list && list[i];i++) {
val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,list[i]));
......@@ -955,12 +1012,16 @@ js_iniGetKeys(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL) {
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
HANDLE_PENDING(cx);
}
array = JS_NewArrayObject(cx, 0, NULL);
rc=JS_SUSPENDREQUEST(cx);
list = iniReadKeyList(p->fp,section);
if(section)
free(section);
JS_RESUMEREQUEST(cx, rc);
for(i=0;list && list[i];i++) {
val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,list[i]));
......@@ -998,14 +1059,18 @@ js_iniGetObject(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc>0 && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
JSVALUE_TO_STRING(cx, argv[0], section, NULL);
if(argc>0 && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL) {
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
HANDLE_PENDING(cx);
}
rc=JS_SUSPENDREQUEST(cx);
list = iniReadNamedStringList(p->fp,section);
if(section)
free(section);
JS_RESUMEREQUEST(cx, rc);
if(list==NULL) { /* New behavior at request of MCMLXXIX: return NULL/undefined if specified section doesn't exist */
if(list==NULL) { /* New behavior at request of MCMLXXIX: return NULL if specified section doesn't exist */
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
return(JS_TRUE);
}
......@@ -1055,8 +1120,14 @@ js_iniSetObject(JSContext *cx, uintN argc, jsval *arglist)
/* property */
JS_IdToValue(cx,id_array->vector[i],&set_argv[1]);
/* value */
JSVALUE_TO_STRING(cx, set_argv[1], p, NULL);
JSVALUE_TO_MSTRING(cx, set_argv[1], p, NULL);
HANDLE_PENDING(cx);
if(p==NULL) {
JS_ReportError(cx, "Invalid NULL property");
return JS_FALSE;
}
JS_GetProperty(cx,object,p,&set_argv[2]);
free(p);
if(!js_iniSetValue_internal(cx,obj,3,set_argv,&rval))
break;
}
......@@ -1074,7 +1145,8 @@ js_iniGetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* name="name";
const char const *name_def="name";
char* name=(char *)name_def;
char* sec_name;
char* prefix=NULL;
char** sec_list;
......@@ -1097,10 +1169,16 @@ js_iniGetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
if(argc)
JSVALUE_TO_STRING(cx, argv[0], name, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], name, NULL);
HANDLE_PENDING(cx);
if(name == NULL) {
JS_ReportError(cx, "Invalid NULL name property");
return JS_FALSE;
}
if(argc>1)
JSVALUE_TO_STRING(cx, argv[1], prefix, NULL);
JSVALUE_TO_MSTRING(cx, argv[1], prefix, NULL);
HANDLE_PENDING(cx);
array = JS_NewArrayObject(cx, 0, NULL);
......@@ -1185,6 +1263,10 @@ http_session_thread(void * 0x00000000) line 5098 + 12 bytes
break;
}
rc=JS_SUSPENDREQUEST(cx);
if(prefix)
free(prefix);
if(name != name_def)
free(name);
iniFreeStringList(sec_list);
JS_RESUMEREQUEST(cx, rc);
......@@ -1198,7 +1280,8 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* name=(char *)"name";
const char const * name_def = "name";
char* name=(char *)name_def;
jsuint i;
jsint j;
jsuint count;
......@@ -1224,7 +1307,12 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
if(argc>1)
JSVALUE_TO_STRING(cx, argv[1], name, NULL);
JSVALUE_TO_MSTRING(cx, argv[1], name, NULL);
HANDLE_PENDING(cx);
if(name==NULL) {
JS_ReportError(cx, "Invalid NULL name property");
return JS_FALSE;
}
/* enumerate the array */
for(i=0; i<count; i++) {
......@@ -1235,16 +1323,25 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
object=JSVAL_TO_OBJECT(oval);
if(!JS_GetProperty(cx, object, name, &set_argv[0]))
continue;
if((id_array=JS_Enumerate(cx,object))==NULL)
if((id_array=JS_Enumerate(cx,object))==NULL) {
if(name != name_def)
free(name);
return(JS_TRUE);
}
for(j=0; j<id_array->length; j++) {
/* property */
JS_IdToValue(cx,id_array->vector[j],&set_argv[1]);
/* check if not name */
JSVALUE_TO_STRING(cx, set_argv[1], p, NULL);
if(strcmp(p,name)==0)
JSVALUE_TO_MSTRING(cx, set_argv[1], p, NULL);
HANDLE_PENDING(cx);
if(p==NULL)
continue;
if(strcmp(p,name)==0) {
free(p);
continue;
}
free(p);
/* value */
JS_GetProperty(cx,object,p,&set_argv[2]);
if(!js_iniSetValue_internal(cx,obj,3,set_argv,&rval))
......@@ -1254,6 +1351,8 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, rval);
JS_DestroyIdArray(cx,id_array);
}
if(name != name_def)
free(name);
return(JS_TRUE);
}
......@@ -1265,7 +1364,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
char* cp;
char* uubuf=NULL;
int len; /* string length */
size_t len; /* string length */
int tlen; /* total length to write (may be greater than len) */
JSString* str;
private_t* p;
......@@ -1284,8 +1383,10 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
if((str = JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_STRING(cx, str, cp, NULL);
len = JS_GetStringLength(str);
JSSTRING_TO_MSTRING(cx, str, cp, &len);
HANDLE_PENDING(cx);
if(cp==NULL)
return JS_TRUE;
rc=JS_SUSPENDREQUEST(cx);
if((p->uuencoded || p->b64encoded || p->yencoded)
......@@ -1298,9 +1399,11 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
len=b64_decode(uubuf,len,cp,len);
if(len<0) {
free(uubuf);
free(cp);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
free(cp);
cp=uubuf;
}
......@@ -1311,7 +1414,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
tlen=len;
if(argc>1) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&tlen)) {
FREE_AND_NULL(uubuf);
free(cp);
return(JS_FALSE);
}
if(len>tlen)
......@@ -1320,24 +1423,29 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
if(fwrite(cp,1,len,p->fp)==(size_t)len) {
free(cp);
if(tlen>len) {
len=tlen-len;
if((cp=malloc(len))==NULL) {
JS_RESUMEREQUEST(cx, rc);
FREE_AND_NULL(uubuf);
dbprintf(TRUE, p, "malloc failure of %u bytes", len);
return(JS_TRUE);
JS_ReportError(cx, "malloc failure of %u bytes", len);
return(JS_FALSE);
}
memset(cp,p->etx,len);
fwrite(cp,1,len,p->fp);
if(fwrite(cp,1,len,p->fp) < len) {
free(cp);
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE;
}
free(cp);
}
dbprintf(FALSE, p, "wrote %u bytes",tlen);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
} else
} else {
free(cp);
dbprintf(TRUE, p, "write of %u bytes failed",len);
}
FREE_AND_NULL(uubuf);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -1346,7 +1454,8 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
static JSBool
js_writeln_internal(JSContext *cx, JSObject *obj, jsval *arg, jsval *rval)
{
char* cp="";
const char const *cp_def="";
char* cp=(char *)cp_def;
JSString* str;
private_t* p;
jsrefcount rc;
......@@ -1366,7 +1475,10 @@ js_writeln_internal(JSContext *cx, JSObject *obj, jsval *arg, jsval *rval)
JS_ReportError(cx,"JS_ValueToString failed");
return(JS_FALSE);
}
JSSTRING_TO_STRING(cx, str, cp, NULL);
JSSTRING_TO_MSTRING(cx, str, cp, NULL);
HANDLE_PENDING(cx);
if(cp==NULL)
cp=(char *)cp_def;
}
rc=JS_SUSPENDREQUEST(cx);
......@@ -1375,6 +1487,8 @@ js_writeln_internal(JSContext *cx, JSObject *obj, jsval *arg, jsval *rval)
if(fprintf(p->fp,"%s\n",cp)!=0)
*rval = JSVAL_TRUE;
if(cp != cp_def)
free(cp);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -2393,16 +2507,20 @@ static void js_finalize_file(JSContext *cx, JSObject *obj)
static JSBool js_file_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);
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
}
return(js_SyncResolve(cx, obj, name, js_file_properties, js_file_functions, NULL, 0));
ret=js_SyncResolve(cx, obj, name, js_file_properties, js_file_functions, NULL, 0);
if(name)
free(name);
return ret;
}
static JSBool js_file_enumerate(JSContext *cx, JSObject *obj)
......@@ -2432,7 +2550,6 @@ js_file_constructor(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
JSString* str;
private_t* p;
char *cstr;
obj=JS_NewObject(cx, &js_file_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
......@@ -2446,8 +2563,7 @@ js_file_constructor(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
JSSTRING_TO_STRING(cx, str, cstr, NULL);
SAFECOPY(p->name,cstr);
JSSTRING_TO_STRBUF(cx, str, p->name, sizeof(p->name), NULL);
if(!JS_SetPrivate(cx, obj, p)) {
dbprintf(TRUE, p, "JS_SetPrivate failed");
......
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