diff --git a/src/sbbs3/js_file.c b/src/sbbs3/js_file.c index cfd0f953198d923f42e1dbdc311359ebabde46c8..a194aa0e350e5c642fbb4aafae7d6ea808e94ff2 100644 --- a/src/sbbs3/js_file.c +++ b/src/sbbs3/js_file.c @@ -404,6 +404,7 @@ js_iniGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva char* section; char* key; char** list; + char buf[MAX_VALUE_LEN]; int32 i; jsval val; jsval dflt=argv[2]; @@ -423,7 +424,7 @@ js_iniGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva case JSVAL_STRING: *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, iniGetString(p->fp,section,key - ,JS_GetStringBytes(JS_ValueToString(cx,dflt))))); + ,JS_GetStringBytes(JS_ValueToString(cx,dflt)),buf))); break; case JSVAL_BOOLEAN: *rval = BOOLEAN_TO_JSVAL( diff --git a/src/sbbs3/sbbs_ini.c b/src/sbbs3/sbbs_ini.c index 7844988274b75c3f026a233da82f6eab9b0fb0b1..371d1ad7621b6be553b0ebe5dbe4cd48fa264082 100644 --- a/src/sbbs3/sbbs_ini.c +++ b/src/sbbs3/sbbs_ini.c @@ -159,11 +159,12 @@ void sbbs_read_ini( char* ctrl_dir; char* temp_dir; char host_name[128]; + char value[MAX_VALUE_LEN]; ulong js_max_bytes; section = "Global"; - ctrl_dir=iniGetString(fp,section,"CtrlDirectory",nulstr); + ctrl_dir=iniGetString(fp,section,"CtrlDirectory",nulstr,value); if(*ctrl_dir) { backslash(ctrl_dir); if(bbs!=NULL) SAFECOPY(bbs->ctrl_dir,ctrl_dir); @@ -171,14 +172,14 @@ void sbbs_read_ini( if(mail!=NULL) SAFECOPY(mail->ctrl_dir,ctrl_dir); if(services!=NULL) SAFECOPY(services->ctrl_dir,ctrl_dir); } - temp_dir=iniGetString(fp,section,"TempDirectory",nulstr); + temp_dir=iniGetString(fp,section,"TempDirectory",nulstr,value); if(*temp_dir) { backslash(temp_dir); if(bbs!=NULL) SAFECOPY(bbs->temp_dir,temp_dir); if(ftp!=NULL) SAFECOPY(ftp->temp_dir,temp_dir); } - SAFECOPY(host_name,iniGetString(fp,section,"HostName",nulstr)); + SAFECOPY(host_name,iniGetString(fp,section,"HostName",nulstr,value)); js_max_bytes=iniGetInteger(fp,section,"JavaScriptMaxBytes",0); /***********************************************************************/ @@ -215,7 +216,7 @@ void sbbs_read_ini( =iniGetInteger(fp,section,"JavaScriptMaxBytes",js_max_bytes); SAFECOPY(bbs->host_name - ,iniGetString(fp,section,"HostName",host_name)); + ,iniGetString(fp,section,"HostName",host_name,value)); /* Set default terminal type to "stock" termcap closest to "ansi-bbs" */ #if defined(__FreeBSD__) @@ -225,9 +226,9 @@ void sbbs_read_ini( #endif SAFECOPY(bbs->xtrn_term_ansi - ,iniGetString(fp,section,"ExternalTermANSI",default_term_ansi)); + ,iniGetString(fp,section,"ExternalTermANSI",default_term_ansi,value)); SAFECOPY(bbs->xtrn_term_dumb - ,iniGetString(fp,section,"ExternalTermDumb","dumb")); + ,iniGetString(fp,section,"ExternalTermDumb","dumb",value)); #if defined(__FreeBSD__) default_dosemu_path="/usr/bin/doscmd"; @@ -236,12 +237,12 @@ void sbbs_read_ini( #endif SAFECOPY(bbs->dosemu_path - ,iniGetString(fp,section,"DOSemuPath",default_dosemu_path)); + ,iniGetString(fp,section,"DOSemuPath",default_dosemu_path,value)); SAFECOPY(bbs->answer_sound - ,iniGetString(fp,section,"AnswerSound",nulstr)); + ,iniGetString(fp,section,"AnswerSound",nulstr,value)); SAFECOPY(bbs->hangup_sound - ,iniGetString(fp,section,"HangupSound",nulstr)); + ,iniGetString(fp,section,"HangupSound",nulstr,value)); bbs->options =iniGetBitField(fp,section,"Options",bbs_options @@ -270,21 +271,21 @@ void sbbs_read_ini( =iniGetInteger(fp,section,"JavaScriptMaxBytes",js_max_bytes); SAFECOPY(ftp->host_name - ,iniGetString(fp,section,"HostName",host_name)); + ,iniGetString(fp,section,"HostName",host_name,value)); SAFECOPY(ftp->index_file_name - ,iniGetString(fp,section,"IndexFileName","00index")); + ,iniGetString(fp,section,"IndexFileName","00index",value)); SAFECOPY(ftp->html_index_file - ,iniGetString(fp,section,"HtmlIndexFile","00index.html")); + ,iniGetString(fp,section,"HtmlIndexFile","00index.html",value)); SAFECOPY(ftp->html_index_script - ,iniGetString(fp,section,"HtmlIndexScript","ftp-html.js")); + ,iniGetString(fp,section,"HtmlIndexScript","ftp-html.js",value)); SAFECOPY(ftp->answer_sound - ,iniGetString(fp,section,"AnswerSound",nulstr)); + ,iniGetString(fp,section,"AnswerSound",nulstr,value)); SAFECOPY(ftp->hangup_sound - ,iniGetString(fp,section,"HangupSound",nulstr)); + ,iniGetString(fp,section,"HangupSound",nulstr,value)); SAFECOPY(ftp->hack_sound - ,iniGetString(fp,section,"HackAttemptSound",nulstr)); + ,iniGetString(fp,section,"HackAttemptSound",nulstr,value)); ftp->options =iniGetBitField(fp,section,"Options",ftp_options @@ -323,30 +324,30 @@ void sbbs_read_ini( =iniGetInteger(fp,section,"MaxMsgSize",10*1024*1024); /* 10MB */ SAFECOPY(mail->host_name - ,iniGetString(fp,section,"HostName",host_name)); + ,iniGetString(fp,section,"HostName",host_name,value)); SAFECOPY(mail->relay_server - ,iniGetString(fp,section,"RelayServer",mail->relay_server)); + ,iniGetString(fp,section,"RelayServer",mail->relay_server,value)); SAFECOPY(mail->dns_server - ,iniGetString(fp,section,"DNSServer",mail->dns_server)); + ,iniGetString(fp,section,"DNSServer",mail->dns_server,value)); SAFECOPY(mail->default_user - ,iniGetString(fp,section,"DefaultUser",nulstr)); + ,iniGetString(fp,section,"DefaultUser",nulstr,value)); SAFECOPY(mail->dnsbl_hdr - ,iniGetString(fp,section,"DNSBlacklistHeader","X-DNSBL")); + ,iniGetString(fp,section,"DNSBlacklistHeader","X-DNSBL",value)); SAFECOPY(mail->dnsbl_tag - ,iniGetString(fp,section,"DNSBlacklistSubject","SPAM")); + ,iniGetString(fp,section,"DNSBlacklistSubject","SPAM",value)); SAFECOPY(mail->pop3_sound - ,iniGetString(fp,section,"POP3Sound",nulstr)); + ,iniGetString(fp,section,"POP3Sound",nulstr,value)); SAFECOPY(mail->inbound_sound - ,iniGetString(fp,section,"InboundSound",nulstr)); + ,iniGetString(fp,section,"InboundSound",nulstr,value)); SAFECOPY(mail->outbound_sound - ,iniGetString(fp,section,"OutboundSound",nulstr)); + ,iniGetString(fp,section,"OutboundSound",nulstr,value)); SAFECOPY(mail->proc_cfg_file - ,iniGetString(fp,section,"ProcessConfigFile","mailproc.cfg")); + ,iniGetString(fp,section,"ProcessConfigFile","mailproc.cfg",value)); mail->options =iniGetBitField(fp,section,"Options",mail_options @@ -368,15 +369,15 @@ void sbbs_read_ini( =iniGetInteger(fp,section,"JavaScriptMaxBytes",js_max_bytes); SAFECOPY(services->host_name - ,iniGetString(fp,section,"HostName",host_name)); + ,iniGetString(fp,section,"HostName",host_name,value)); SAFECOPY(services->cfg_file - ,iniGetString(fp,section,"ConfigFile","services.cfg")); + ,iniGetString(fp,section,"ConfigFile","services.cfg",value)); SAFECOPY(services->answer_sound - ,iniGetString(fp,section,"AnswerSound",nulstr)); + ,iniGetString(fp,section,"AnswerSound",nulstr,value)); SAFECOPY(services->hangup_sound - ,iniGetString(fp,section,"HangupSound",nulstr)); + ,iniGetString(fp,section,"HangupSound",nulstr,value)); services->options =iniGetBitField(fp,section,"Options",service_options @@ -399,12 +400,12 @@ void sbbs_read_ini( =iniGetInteger(fp,section,"JavaScriptMaxBytes",js_max_bytes); SAFECOPY(web->host_name - ,iniGetString(fp,section,"HostName",host_name)); + ,iniGetString(fp,section,"HostName",host_name,value)); SAFECOPY(web->root_dir - ,iniGetString(fp,section,"RootDirectory","../html")); + ,iniGetString(fp,section,"RootDirectory","../html",value)); SAFECOPY(web->error_dir - ,iniGetString(fp,section,"ErrorDirectory","../html/error")); + ,iniGetString(fp,section,"ErrorDirectory","../html/error",value)); iniFreeStringList(web->index_file_name); web->index_file_name @@ -413,7 +414,7 @@ void sbbs_read_ini( web->cgi_ext =iniGetStringList(fp,section,"CGIExtensions", "," ,".cgi"); SAFECOPY(web->ssjs_ext - ,iniGetString(fp,section,"JavaScriptExtension",".ssjs")); + ,iniGetString(fp,section,"JavaScriptExtension",".ssjs",value)); web->max_inactivity =iniGetShortInt(fp,section,"MaxInactivity",120); /* seconds */ @@ -428,7 +429,7 @@ void sbbs_read_ini( default_cgi_temp = nulstr; #endif SAFECOPY(web->cgi_temp_dir - ,iniGetString(fp,section,"CGITempDirectory",default_cgi_temp)); + ,iniGetString(fp,section,"CGITempDirectory",default_cgi_temp,value)); web->options =iniGetBitField(fp,section,"Options",web_options diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index c71459df75a943e9e0cd2ecca03f59b876910648..4927d30d732579e75e1b7d059b4d267afbc51019 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -41,9 +41,6 @@ #include "sockwrap.h" /* inet_addr */ #include "ini_file.h" -#define MAX_LINE_LEN 256 /* includes '\0' */ -#define MAX_VALUE_LEN 128 /* includes '\0' */ - /****************************************************************************/ /* Truncates white-space chars off end of 'str' */ /****************************************************************************/ @@ -82,12 +79,11 @@ static BOOL find_section(FILE* fp, const char* section) return(FALSE); } -static char* get_value(FILE* fp, const char* section, const char* key) +static char* get_value(FILE* fp, const char* section, const char* key, char* value) { char* p; char* tp; char str[MAX_LINE_LEN]; - static char value[MAX_VALUE_LEN]; if(fp==NULL) return(NULL); @@ -115,18 +111,16 @@ static char* get_value(FILE* fp, const char* section, const char* key) p=tp+1; while(*p && *p<=' ') p++; truncsp(p); - SAFECOPY(value,p); + sprintf(value,"%.*s",MAX_VALUE_LEN-1,p); return(value); } return(NULL); } -char* iniGetString(FILE* fp, const char* section, const char* key, const char* deflt) +char* iniGetString(FILE* fp, const char* section, const char* key, const char* deflt, char* value) { - char* value; - - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,value))==NULL) return((char*)deflt); if(*value==0) /* blank value */ @@ -139,13 +133,14 @@ char** iniGetStringList(FILE* fp, const char* section, const char* key ,const char* sep, const char* deflt) { char* value; + char buf[MAX_VALUE_LEN]; char** lp; char** np; char* token; char list[MAX_VALUE_LEN]; ulong items=0; - if((value=get_value(fp,section,key))==NULL || *value==0 /* blank */) + if((value=get_value(fp,section,key,buf))==NULL || *value==0 /* blank */) value=(char*)deflt; SAFECOPY(list,value); @@ -363,9 +358,10 @@ iniGetNamedStringList(FILE* fp, const char* section) long iniGetInteger(FILE* fp, const char* section, const char* key, long deflt) { - char* value; + char* value; + char buf[MAX_VALUE_LEN]; - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,buf))==NULL) return(deflt); if(*value==0) /* blank value */ @@ -381,9 +377,10 @@ ushort iniGetShortInt(FILE* fp, const char* section, const char* key, ushort def ulong iniGetIpAddress(FILE* fp, const char* section, const char* key, ulong deflt) { - char* value; + char buf[MAX_VALUE_LEN]; + char* value; - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,buf))==NULL) return(deflt); if(*value==0) /* blank value */ @@ -397,9 +394,10 @@ ulong iniGetIpAddress(FILE* fp, const char* section, const char* key, ulong defl double iniGetFloat(FILE* fp, const char* section, const char* key, double deflt) { - char* value; + char buf[MAX_VALUE_LEN]; + char* value; - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,buf))==NULL) return(deflt); if(*value==0) /* blank value */ @@ -410,9 +408,10 @@ double iniGetFloat(FILE* fp, const char* section, const char* key, double deflt) BOOL iniGetBool(FILE* fp, const char* section, const char* key, BOOL deflt) { - char* value; + char buf[MAX_VALUE_LEN]; + char* value; - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,buf))==NULL) return(deflt); if(*value==0) /* blank value */ @@ -433,9 +432,10 @@ ulong iniGetBitField(FILE* fp, const char* section, const char* key, char* p; char* tp; char* value; + char buf[MAX_VALUE_LEN]; ulong v=0; - if((value=get_value(fp,section,key))==NULL) + if((value=get_value(fp,section,key,buf))==NULL) return(deflt); for(p=value;*p;) { diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index 39865251d8dcc0e984af14a3d49f0df8f1e4059d..18578915caf334bb2fa3ee23bbc2b31436650a12 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -40,6 +40,9 @@ #include "genwrap.h" +#define MAX_LINE_LEN 256 /* Maximum length of entire line, includes '\0' */ +#define MAX_VALUE_LEN 128 /* Maximum value length, includes '\0' */ + typedef struct { ulong bit; const char* name; @@ -49,9 +52,9 @@ typedef struct { extern "C" { #endif -/* Read all section names and return as a string list */ +/* Read all section names and return as an allocated string list */ char** iniGetSectionList (FILE* fp); -/* Read all key names and return as a string list */ +/* Read all key names and return as an allocated string list */ char** iniGetKeyList (FILE* fp, const char* section); /* Read all key and value pairs and return as a named string list */ named_string_t** @@ -59,7 +62,7 @@ named_string_t** /* These functions read a single key of the specified type */ char* iniGetString (FILE* fp, const char* section, const char* key, - const char* deflt); + const char* deflt, char* value); char** iniGetStringList(FILE* fp, const char* section, const char* key ,const char* sep, const char* deflt); long iniGetInteger (FILE* fp, const char* section, const char* key,