From: Pasi Kallinen Date: Tue, 11 Oct 2011 18:05:11 +0000 (+0000) Subject: Make bannerstrmangle able to handle arbitrarily long strings. X-Git-Tag: v1.6.1-roc-dev~87 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=5a0c90fa0f56ce25c03137d023d106d87bf1c0dc;p=dgamelaunch Make bannerstrmangle able to handle arbitrarily long strings. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@623 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- diff --git a/TODO b/TODO index f6a627b..38898c3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ +-update dgamelaunch.8 + -occasionally dgl crashes, leaving the shmem semaphore in a state where the shmem block has to be freed. @@ -19,8 +21,6 @@ (needs some way to name the options given as keys... maybe another format for the keys that includes a string to be used as the name) --document the exit (error) codes. - -cursor keys are not restored after watching a game of curses-nethack. @@ -126,8 +126,6 @@ or maybe add a new command '' set_charstrip "name" '' -configurable stuff: allowed chars in usernames, allow char stripping, ... -- Flags for operators/staff/admins or (optionally) user-bans. - - Localization of variables, code clean up - Use /var/run/nologin and/or dgl-specific nologin file diff --git a/dgamelaunch.c b/dgamelaunch.c index 6f1c2de..f7b6f18 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -371,22 +371,21 @@ idle_alarm_reset(void) char * -bannerstrmangle(char *buf, char *fromstr, char *tostr) +bannerstrmangle(char *buf, char *bufnew, int buflen, char *fromstr, char *tostr) { - static char bufnew[81]; char *loc; char *b = buf; - memset (bufnew, 0, 80); + memset (bufnew, 0, buflen); if (strstr(b, fromstr)) { int i = 0; while ((loc = strstr (b, fromstr)) != NULL) { - for (; i < 80; i++) { + for (; i < buflen; i++) { if (loc != b) bufnew[i] = *(b++); else { - strlcat (bufnew, tostr, 80); + strlcat (bufnew, tostr, buflen); b += strlen(fromstr); i += strlen(tostr); break; @@ -398,9 +397,8 @@ bannerstrmangle(char *buf, char *fromstr, char *tostr) } if (*b) - strlcat(bufnew, b, 80); - } else strncpy(bufnew, buf, 80); - + strlcat(bufnew, b, buflen); + } else strncpy(bufnew, buf, buflen); return bufnew; } @@ -516,16 +514,17 @@ loadbanner (char *fname, struct dg_banner *ban) } } } else { + char tmpbufnew[80]; struct dg_banner_var *bv = globalconfig.banner_var_list; while (bv) { - strncpy(bufnew, bannerstrmangle(bufnew, bv->name, bv->value), 80); + strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, bv->name, bv->value), 80); bv = bv->next; } - strncpy(bufnew, bannerstrmangle(bufnew, "$VERSION", PACKAGE_STRING), 80); + strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$VERSION", PACKAGE_STRING), 80); if (me && loggedin) { - strncpy(bufnew, bannerstrmangle(bufnew, "$USERNAME", me->username), 80); + strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$USERNAME", me->username), 80); } else { - strncpy(bufnew, bannerstrmangle(bufnew, "$USERNAME", "[Anonymous]"), 80); + strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$USERNAME", "[Anonymous]"), 80); } banner_addline(ban, bufnew); }