From d9fac6178cbf83789cee2a8e3ae3cef4c9159cdb Mon Sep 17 00:00:00 2001 From: joonicks Date: Tue, 27 Mar 2018 23:26:34 +0200 Subject: [PATCH] Free() panics are no longer deadly --- VERSIONS | 2 ++ configure | 2 +- src/function.c | 3 ++- src/global.h | 1 + src/main.c | 21 +++++++++++++++++++-- src/toybox.c | 8 ++------ src/urlcap.c | 1 + src/user.c | 40 ++++++++++++++++++++++++++++++++++------ 8 files changed, 62 insertions(+), 16 deletions(-) diff --git a/VERSIONS b/VERSIONS index 8c75e54..e35175b 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,5 +1,7 @@ 3.0.99p4 -- WORK IN PROGRESS (~March, 2018) + * Changed: If compiled with debug, Free() on unknown memory no longer shuts down the bot, + now it just ignores the panic and swallows the (possible) leak. * Added: Experimental code to suppress certain commands to run on only one bot even if command is issued in public. * Added: Some example ascii art: bbw, camel, goatse, mech, phooler diff --git a/configure b/configure index 24a7e75..4fc0b00 100755 --- a/configure +++ b/configure @@ -1011,7 +1011,7 @@ test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ def_suppress='#undef SUPPRESS' unset ans -$out $ac_n "[ ALPHA] Command duplication suppression? ............ [Y/n] "$ac_c +$out $ac_n "[ ALPHA] Command duplication suppression? ........... [Y/n] "$ac_c test "$ft_suppress" && $out "$ft_suppress" && ans=$ft_suppress test -z "$ft_suppress" && read ans test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes && def_suppress='#define SUPPRESS' diff --git a/src/function.c b/src/function.c index d3644ea..0d95ef4 100644 --- a/src/function.c +++ b/src/function.c @@ -126,7 +126,8 @@ void Free(char **mem) { debug("(Free) PANIC: Free(0x"mx_pfmt"); Unregistered memory block\n",(mx_ptr)src); run_debug(); - exit(1); + //exit(1); // overreacting. just ignore it and accept the leak. + return; } mp = mp->next; } diff --git a/src/global.h b/src/global.h index 740f242..fe76dd5 100644 --- a/src/global.h +++ b/src/global.h @@ -82,6 +82,7 @@ BEG int makecore MDEF(FALSE); BEG int respawn MDEF(0); BEG int sigmaster MDEF(0); BEG int ctimeout MDEF(30); /* proc var */ +BEG int startup MDEF(TRUE); BEG ino_t parent_inode; BEG KillSock *killsocks MDEF(NULL); diff --git a/src/main.c b/src/main.c index cd16d01..ce7645e 100644 --- a/src/main.c +++ b/src/main.c @@ -818,6 +818,9 @@ int main(int argc, char **argv, char **envp) char *opt; int do_fork = TRUE; int versiononly = FALSE; +#ifdef NEWBIE + int n = 0; +#endif uptime = time(&now); @@ -1017,12 +1020,12 @@ execve( ./energymech, argv = { ./energymech }, envp LocalBot.x.x.aop = 1; LocalBot.chan = CoreUser.chan = (Strp*)&CMA; + readcfgfile(); + #ifdef UPTIME init_uptime(); #endif /* UPTIME */ - readcfgfile(); - #ifndef I_HAVE_A_LEGITIMATE_NEED_FOR_MORE_THAN_4_BOTS if (spawning_lamer > 4) { @@ -1035,7 +1038,20 @@ execve( ./energymech, argv = { ./energymech }, envp { if ((opt = current->setting[STR_USERFILE].str_var)) read_userlist(opt); +#ifdef NEWBIE + if (current->userlist == NULL) + { + to_file(1,"init: No userlist loaded for %s\n",nullstr(current->nick)); + n++; + } } + if (n) + { + _exit(1); + } +#else + } +#endif /* NEWBIE */ for(current=botlist;current;current=current->next) { mirror_userlist(); @@ -1104,5 +1120,6 @@ execve( ./energymech, argv = { ./energymech }, envp #endif /* DEBUG */ } + startup = FALSE; doit(); } diff --git a/src/toybox.c b/src/toybox.c index b4c809d..520fdf0 100644 --- a/src/toybox.c +++ b/src/toybox.c @@ -149,12 +149,8 @@ int read_bigcharset(char *fname) { bigc = orig_fontlist; orig_fontlist = bigc->next; - while(bigc->data) - { - sp = bigc->data; - bigc->data = sp->next; - Free((char**)&sp); - } + if (bigc->data) + purge_strplist(bigc->data); Free((char**)&bigc); } diff --git a/src/urlcap.c b/src/urlcap.c index 4f560e2..52dd766 100644 --- a/src/urlcap.c +++ b/src/urlcap.c @@ -56,6 +56,7 @@ void urlcapture(const char *rest) if (n <= 0) { purge_strplist(sp->next); + sp->next = NULL; return; } n--; diff --git a/src/user.c b/src/user.c index f0297f9..518e6d3 100644 --- a/src/user.c +++ b/src/user.c @@ -296,36 +296,64 @@ int read_userlist(char *filename) int in; #ifdef DEBUG int r; -#endif -#ifdef DEBUG if (!filename) { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE filename empty\n"); +#endif /* NEWBIE */ debug("(read_userlist) filename is NULL\n"); return(FALSE); } if (*filename == '<') // read only userfile filename++; - if ((r = is_safepath(filename,FILE_MUST_EXIST)) != FILE_IS_SAFE) + if ((r = is_safepath(filename,FILE_MAY_EXIST)) != FILE_IS_SAFE) { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE filename is unsafe\n"); +#endif /* NEWBIE */ debug("(read_userlist) %s: unsafe filename (%i)...\n",filename,r); return(FALSE); } if ((in = open(filename,O_RDONLY)) < 0) { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE \"%s\": %s\n",filename,strerror(errno)); +#endif /* NEWBIE */ debug("(read_userlist) failed to open \"%s\": %s\n",filename,strerror(errno)); return(FALSE); } -#else +#else /* ifdef DEBUG */ if (!filename) + { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE filename empty\n"); +#endif /* NEWBIE */ return(FALSE); + } if (*filename == '<') // read only userfile filename++; - if (is_safepath(filename,FILE_MUST_EXIST) != FILE_IS_SAFE) + if (is_safepath(filename,FILE_MAY_EXIST) != FILE_IS_SAFE) + { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE filename is unsafe\n"); +#endif /* NEWBIE */ return(FALSE); + } if ((in = open(filename,O_RDONLY)) < 0) + { +#ifdef NEWBIE + if (startup) + to_file(1,"read_userlist: USERFILE \"%s\": %s\n",filename,strerror(errno)); +#endif /* NEWBIE */ return(FALSE); -#endif + } +#endif /* ifdef DEBUG */ olduserlist = current->userlist; cfgUser = current->userlist = NULL;