Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit fefbd96f authored by rswindell's avatar rswindell

Address Coverity-reported issues.

parent 44bca1ea
......@@ -1142,8 +1142,8 @@ js_lfexpand(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
if((outbuf=(char*)malloc((strlen(inbuf)*2)+1))==NULL) {
free(inbuf);
JS_ReportError(cx, "Error allocating %lu bytes at %s:%d", (strlen(inbuf)*2)+1, getfname(__FILE__), __LINE__);
free(inbuf);
return(JS_FALSE);
}
......@@ -1268,10 +1268,10 @@ js_quote_msg(JSContext *cx, uintN argc, jsval *arglist)
}
if((outbuf=(char*)malloc((strlen(inbuf)*(strlen(prefix)+1))+1))==NULL) {
JS_ReportError(cx, "Error allocating %lu bytes at %s:%d", (strlen(inbuf)*(strlen(prefix)+1))+1, getfname(__FILE__), __LINE__);
free(inbuf);
if(prefix != prefix_def)
free(prefix);
JS_ReportError(cx, "Error allocating %lu bytes at %s:%d", (strlen(inbuf)*(strlen(prefix)+1))+1, getfname(__FILE__), __LINE__);
return(JS_FALSE);
}
......@@ -2529,6 +2529,7 @@ js_b64_decode(JSContext *cx, uintN argc, jsval *arglist)
if((outbuf=(char*)malloc(len))==NULL) {
JS_ReportError(cx, "Error allocating %lu bytes at %s:%d", len, getfname(__FILE__), __LINE__);
free(inbuf);
return(JS_FALSE);
}
......@@ -2703,8 +2704,10 @@ js_truncstr(JSContext *cx, uintN argc, jsval *arglist)
free(str);
return JS_FALSE;
}
if(set==NULL)
if(set==NULL) {
free(str);
return(JS_TRUE);
}
truncstr(str,set);
free(set);
......@@ -3339,8 +3342,11 @@ js_fmutex(JSContext *cx, uintN argc, jsval *arglist)
}
}
if(argc > argn && JSVAL_IS_NUMBER(argv[argn])) {
if(!JS_ValueToInt32(cx, argv[argn++], &max_age))
if(!JS_ValueToInt32(cx, argv[argn++], &max_age)) {
FREE_AND_NULL(text);
free(fname);
return JS_FALSE;
}
}
rc=JS_SUSPENDREQUEST(cx);
......@@ -3821,8 +3827,10 @@ js_resolve_ip(JSContext *cx, uintN argc, jsval *arglist)
if(want_array) {
JS_RESUMEREQUEST(cx, rc);
if((rarray = JS_NewArrayObject(cx, 0, NULL))==NULL)
if((rarray = JS_NewArrayObject(cx, 0, NULL))==NULL) {
freeaddrinfo(res);
return(JS_FALSE);
}
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(rarray));
for(cur=res; cur; cur=cur->ai_next) {
inet_addrtop((void *)cur->ai_addr, ip_str, sizeof(ip_str));
......@@ -3883,6 +3891,7 @@ js_resolve_host(JSContext *cx, uintN argc, jsval *arglist)
hints.ai_flags = NI_NAMEREQD;
if(getnameinfo(res->ai_addr, res->ai_addrlen, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD)!=0) {
JS_RESUMEREQUEST(cx, rc);
freeaddrinfo(res);
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
......@@ -4498,29 +4507,37 @@ BOOL DLLCALL js_CreateGlobalObject(JSContext* cx, scfg_t* cfg, jsSyncMethodSpec*
p->startup = startup;
p->exit_func=NULL;
if((*glob = JS_NewCompartmentAndGlobalObject(cx, &js_global_class, NULL)) ==NULL)
if((*glob = JS_NewCompartmentAndGlobalObject(cx, &js_global_class, NULL)) ==NULL) {
free(p);
return(FALSE);
if(!JS_AddObjectRoot(cx, glob))
}
if(!JS_AddObjectRoot(cx, glob)) {
free(p);
return(FALSE);
}
if(!JS_SetPrivate(cx, *glob, p)) { /* Store a pointer to scfg_t and the new methods */
JS_RemoveObjectRoot(cx, glob);
free(p);
return(FALSE);
}
if (!JS_InitStandardClasses(cx, *glob)) {
JS_RemoveObjectRoot(cx, glob);
free(p);
return(FALSE);
}
p->bg_count=0;
if(sem_init(&p->bg_sem, 0, 0)==-1) {
JS_RemoveObjectRoot(cx, glob);
free(p);
return(FALSE);
}
if (!JS_SetReservedSlot(cx, *glob, 0, INT_TO_JSVAL(0))) {
JS_RemoveObjectRoot(cx, glob);
free(p);
return(FALSE);
}
......
......@@ -1452,6 +1452,7 @@ js_get_msg_header(JSContext *cx, uintN argc, jsval *arglist)
if((p->p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
free(p);
return JS_FALSE;
}
......@@ -1468,28 +1469,35 @@ js_get_msg_header(JSContext *cx, uintN argc, jsval *arglist)
/* Now parse message offset/id and get message */
if(JSVAL_IS_NUMBER(argv[n])) {
if(by_offset) { /* Get by offset */
if(!JS_ValueToInt32(cx,argv[n++],(int32*)&(p->msg).offset))
if(!JS_ValueToInt32(cx,argv[n++],(int32*)&(p->msg).offset)) {
free(p);
return JS_FALSE;
}
}
else { /* Get by number */
if(!JS_ValueToInt32(cx,argv[n++],(int32*)&(p->msg).hdr.number))
if(!JS_ValueToInt32(cx,argv[n++],(int32*)&(p->msg).hdr.number)) {
free(p);
return JS_FALSE;
}
}
rc=JS_SUSPENDREQUEST(cx);
if((p->p->status=smb_getmsgidx(&(p->p->smb), &(p->msg)))!=SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
free(p);
return JS_TRUE;
}
if((p->p->status=smb_lockmsghdr(&(p->p->smb),&(p->msg)))!=SMB_SUCCESS) {
JS_RESUMEREQUEST(cx, rc);
free(p);
return JS_TRUE;
}
if((p->p->status=smb_getmsghdr(&(p->p->smb), &(p->msg)))!=SMB_SUCCESS) {
smb_unlockmsghdr(&(p->p->smb),&(p->msg));
JS_RESUMEREQUEST(cx, rc);
free(p);
return JS_TRUE;
}
......@@ -1499,19 +1507,24 @@ js_get_msg_header(JSContext *cx, uintN argc, jsval *arglist)
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(argv[n]), cstr, NULL);
n++;
HANDLE_PENDING(cx, cstr);
rc=JS_SUSPENDREQUEST(cx);
if((p->p->status=smb_getmsghdr_by_msgid(&(p->p->smb),&(p->msg)
,cstr))!=SMB_SUCCESS) {
if(cstr != NULL) {
rc=JS_SUSPENDREQUEST(cx);
if((p->p->status=smb_getmsghdr_by_msgid(&(p->p->smb),&(p->msg)
,cstr))!=SMB_SUCCESS) {
free(cstr);
JS_RESUMEREQUEST(cx, rc);
free(p);
return JS_TRUE; /* ID not found */
}
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE; /* ID not found */
}
free(cstr);
JS_RESUMEREQUEST(cx, rc);
}
if(p->msg.hdr.number==0) /* No valid message number/id/offset specified */
if(p->msg.hdr.number==0) { /* No valid message number/id/offset specified */
free(p);
return JS_TRUE;
}
if(JSVAL_IS_BOOLEAN(argv[n]))
p->expand_fields = JSVAL_TO_BOOLEAN(argv[n++]);
......@@ -1521,6 +1534,7 @@ js_get_msg_header(JSContext *cx, uintN argc, jsval *arglist)
if(!include_votes && (p->msg.hdr.attr&MSG_VOTE)) {
smb_freemsgmem(&(p->msg));
free(p);
return JS_TRUE;
}
......@@ -1536,6 +1550,7 @@ js_get_msg_header(JSContext *cx, uintN argc, jsval *arglist)
if((hdrobj=JS_NewObject(cx,&js_msghdr_class,proto,obj))==NULL) {
smb_freemsgmem(&(p->msg));
free(p);
return JS_TRUE;
}
......@@ -1844,7 +1859,7 @@ js_remove_msg(JSContext *cx, uintN argc, jsval *arglist)
JSBool msg_specified=JS_FALSE;
smbmsg_t msg;
private_t* p;
char* cstr;
char* cstr = NULL;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
......@@ -1877,15 +1892,18 @@ js_remove_msg(JSContext *cx, uintN argc, jsval *arglist)
} else if(JSVAL_IS_STRING(argv[n])) { /* Get by ID */
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(argv[n]), cstr, NULL);
HANDLE_PENDING(cx, cstr);
if(cstr == NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
if(!msg_offset_by_id(p
,cstr
,&msg.offset)) {
free(p);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE; /* ID not found */
}
free(p);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
msg_specified=JS_TRUE;
n++;
......@@ -1893,8 +1911,10 @@ js_remove_msg(JSContext *cx, uintN argc, jsval *arglist)
}
}
if(!msg_specified)
if(!msg_specified) {
free(p);
return JS_TRUE;
}
rc=JS_SUSPENDREQUEST(cx);
if((p->status=smb_getmsgidx(&(p->smb), &msg))==SMB_SUCCESS
......@@ -1906,6 +1926,7 @@ js_remove_msg(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
}
free(p);
smb_freemsgmem(&msg);
JS_RESUMEREQUEST(cx, rc);
......@@ -2271,10 +2292,10 @@ js_save_msg(JSContext *cx, uintN argc, jsval *arglist)
body=strdup("");
if(rcpt_list!=NULL) {
if(!JS_GetArrayLength(cx, rcpt_list, &rcpt_list_length))
return JS_TRUE;
if(!rcpt_list_length)
if(!JS_GetArrayLength(cx, rcpt_list, &rcpt_list_length) || !rcpt_list_length) {
free(body);
return JS_TRUE;
}
}
if(parse_header_object(cx, p, hdr, &msg, rcpt_list==NULL)) {
......@@ -2508,6 +2529,7 @@ js_how_user_voted(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
votes = smb_voted_already(&(p->smb), msgnum, name, NET_NONE, NULL);
free(name);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,UINT_TO_JSVAL(votes));
......@@ -2549,6 +2571,7 @@ js_close_poll(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
result = closepoll(scfg, &(p->smb), msgnum, name);
free(name);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, result == SMB_SUCCESS ? JSVAL_TRUE : JSVAL_FALSE);
......@@ -2973,7 +2996,12 @@ js_msgbase_constructor(JSContext *cx, uintN argc, jsval *arglist)
js_str = JS_ValueToString(cx, argv[0]);
JSSTRING_TO_MSTRING(cx, js_str, base, NULL);
HANDLE_PENDING(cx, base);
if(JS_IsExceptionPending(cx)) {
if(base != NULL)
free(base);
free(p);
return JS_FALSE;
}
if(base==NULL) {
JS_ReportError(cx, "Invalid base parameter");
free(p);
......
......@@ -206,10 +206,13 @@ static queued_value_t* js_encode_value(JSContext *cx, jsval val, char* name)
if(name!=NULL)
SAFECOPY(v->name,name);
if(!JS_WriteStructuredClone(cx, val, &serialized, &v->size, NULL, NULL))
if(!JS_WriteStructuredClone(cx, val, &serialized, &v->size, NULL, NULL)) {
free(v);
return NULL;
}
if((v->value=(uint64 *)malloc(v->size))==NULL) {
JS_free(cx, serialized);
free(v);
return NULL;
}
memcpy(v->value, serialized, v->size);
......
......@@ -875,7 +875,6 @@ js_sendfile(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
free(fname);
len = js_socket_sendfilesocket(p, file, NULL, 0);
close(file);
......@@ -886,6 +885,7 @@ js_sendfile(JSContext *cx, uintN argc, jsval *arglist)
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %s failed",fname);
}
free(fname);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -2123,6 +2123,7 @@ js_socket_constructor(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
FREE_AND_NULL(protocol);
return JS_TRUE;
}
else
......@@ -2151,6 +2152,7 @@ js_socket_constructor(JSContext *cx, uintN argc, jsval *arglist)
JS_ReportError(cx,"open_socket failed with error %d",ERROR_VALUE);
if(protocol)
free(protocol);
free(p);
return(JS_FALSE);
}
if(protocol)
......@@ -2162,6 +2164,7 @@ js_socket_constructor(JSContext *cx, uintN argc, jsval *arglist)
if(!JS_SetPrivate(cx, obj, p)) {
JS_ReportError(cx,"JS_SetPrivate failed");
free(p);
return(JS_FALSE);
}
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2013 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -68,6 +68,7 @@ js_sprintf(JSContext *cx, uint argn, uintN argc, jsval *argv)
JS_ClearPendingException(cx);
if(p2==NULL) {
free(p);
free(op);
return NULL;
}
p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_CHARP,p2);
......
......@@ -1125,7 +1125,7 @@ js_spamlog(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
char* p;
char* p=NULL;
char* prot=NULL;
char* action=NULL;
char* reason=NULL;
......@@ -1162,27 +1162,29 @@ js_spamlog(JSContext *cx, uintN argc, jsval *arglist)
free(to);
if(from)
free(from);
if(p)
free(p);
return JS_FALSE;
}
if(p==NULL)
continue;
if(prot==NULL)
prot=p;
else if(action==NULL)
action=p;
else if(reason==NULL)
reason=p;
else if(host==NULL)
host=p;
else if(ip_addr==NULL)
ip_addr=p;
else if(to==NULL)
to=p;
else if(from==NULL)
from=p;
else
free(p);
}
if(p==NULL)
continue;
if(prot==NULL)
prot=p;
else if(action==NULL)
action=p;
else if(reason==NULL)
reason=p;
else if(host==NULL)
host=p;
else if(ip_addr==NULL)
ip_addr=p;
else if(to==NULL)
to=p;
else if(from==NULL)
from=p;
else
free(p);
}
rc=JS_SUSPENDREQUEST(cx);
ret=spamlog(cfg,prot,action,reason,host,ip_addr,to,from);
......@@ -1212,7 +1214,7 @@ js_hacklog(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
int32 i32=0;
char* p;
char* p=NULL;
char* prot=NULL;
char* user=NULL;
char* text=NULL;
......@@ -1250,6 +1252,8 @@ js_hacklog(JSContext *cx, uintN argc, jsval *arglist)
free(text);
if(host)
free(host);
if(p)
free(p);
return JS_FALSE;
}
}
......@@ -1285,7 +1289,7 @@ js_filter_ip(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
char* p;
char* p=NULL;
char* prot=NULL;
char* reason=NULL;
char* host=NULL;
......@@ -1319,6 +1323,8 @@ js_filter_ip(JSContext *cx, uintN argc, jsval *arglist)
free(from);
if(fname)
free(fname);
if(p)
free(p);
return JS_FALSE;
}
}
......
......@@ -619,8 +619,11 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
free(prompt);
return JS_FALSE;
}
if(org==NULL)
if(org==NULL) {
if(prompt)
free(prompt);
return(JS_TRUE);
}
}
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&maxlen)) {
......@@ -724,7 +727,8 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
if(JS_IsArrayObject(cx, objarg)) {
if(!JS_GetArrayLength(cx, objarg, &numopts))
return(JS_TRUE);
opts=strListInit();
if(opts == NULL)
opts=strListInit();
for(i=0;i<numopts;i++) {
if(!JS_GetElement(cx, objarg, i, &val))
break;
......@@ -735,8 +739,7 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
}
strListPush(&opts,opt);
}
if(opt)
free(opt);
FREE_AND_NULL(opt);
}
else if(JS_GetClass(cx, objarg) == &js_uifc_list_ctx_class) {
p = JS_GetPrivate(cx, objarg);
......@@ -757,6 +760,8 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
}
strListFree(&opts);
if(title != NULL)
free(title);
return(JS_TRUE);
}
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2014 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -1500,6 +1500,7 @@ js_user_constructor(JSContext *cx, uintN argc, jsval *arglist)
if(argc && (!JS_ValueToInt32(cx,argv[0],&val)))
return JS_FALSE;
memset(&user, 0, sizeof(user));
user.number=(ushort)val;
if(user.number!=0 && (i=getuserdat(scfg,&user))!=0) {
JS_ReportError(cx,"Error %d reading user number %d",i,val);
......
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