diff options
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/adminproc.c | 62 | ||||
-rw-r--r-- | FICS/comproc.c | 25 |
2 files changed, 57 insertions, 30 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c index 94a9448..04331a4 100644 --- a/FICS/adminproc.c +++ b/FICS/adminproc.c @@ -613,45 +613,57 @@ com_checkPLAYER(int p, param_list param) pprintf(p, "%s is not logged in.\n", v_player); stolower(v_player); - pprintf(p, "name = %s\n", parray[p1].name); - pprintf(p, "login = %s\n", parray[p1].login); - pprintf(p, "fullName = %s\n", (parray[p1].fullName ? - parray[p1].fullName : "(none)")); - pprintf(p, "emailAddress = %s\n", (parray[p1].emailAddress ? - parray[p1].emailAddress : "(none)")); - pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); + pprintf(p, "name = %s\n", parray[p1].name); + pprintf(p, "login = %s\n", parray[p1].login); + pprintf(p, "fullName = %s\n", + (parray[p1].fullName + ? parray[p1].fullName + : "(none)")); + pprintf(p, "emailAddress = %s\n", + (parray[p1].emailAddress + ? parray[p1].emailAddress + : "(none)")); + pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); #if 0 pprintf(p, "network_player = %d\n", parray[p1].network_player); #endif - pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); - pprintf(p, "num_comments = %d\n", parray[p1].num_comments); + pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); + pprintf(p, "num_comments = %d\n", parray[p1].num_comments); player_remove(p1); return COM_OK; } else { + char tbuf[30] = { '\0' }; + p1 = p1 - 1; pprintf(p, "%s is number %d in parray of size %d\n", v_player, p1, (p_num + 1)); - pprintf(p, "name = %s\n", parray[p1].name); - pprintf(p, "login = %s\n", parray[p1].login); - pprintf(p, "fullName = %s\n", (parray[p1].fullName ? - parray[p1].fullName : "(none)")); - pprintf(p, "emailAddress = %s\n", (parray[p1].emailAddress ? - parray[p1].emailAddress : "(none)")); - pprintf(p, "socket = %d\n", parray[p1].socket); - pprintf(p, "registered = %d\n", parray[p1].registered); - pprintf(p, "last_tell = %d\n", parray[p1].last_tell); - pprintf(p, "last_channel = %d\n", parray[p1].last_channel); - pprintf(p, "logon_time = %s", - ctime((time_t *) &parray[p1].logon_time)); - pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); + pprintf(p, "name = %s\n", parray[p1].name); + pprintf(p, "login = %s\n", parray[p1].login); + pprintf(p, "fullName = %s\n", + (parray[p1].fullName + ? parray[p1].fullName + : "(none)")); + pprintf(p, "emailAddress = %s\n", + (parray[p1].emailAddress + ? parray[p1].emailAddress + : "(none)")); + pprintf(p, "socket = %d\n", parray[p1].socket); + pprintf(p, "registered = %d\n", parray[p1].registered); + pprintf(p, "last_tell = %d\n", parray[p1].last_tell); + pprintf(p, "last_channel = %d\n", parray[p1].last_channel); + pprintf(p, "logon_time = %s", + (ctime_r(&parray[p1].logon_time, tbuf) != NULL + ? &tbuf[0] + : "n/a")); + pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); #if 0 pprintf(p, "network_player = %d\n", parray[p1].network_player); #endif - pprintf(p, "thisHost = %s\n", dotQuad(parray[p1].thisHost)); - pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); - pprintf(p, "num_comments = %d\n", parray[p1].num_comments); + pprintf(p, "thisHost = %s\n", dotQuad(parray[p1].thisHost)); + pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); + pprintf(p, "num_comments = %d\n", parray[p1].num_comments); } return COM_OK; diff --git a/FICS/comproc.c b/FICS/comproc.c index b377cc8..a7a5ea1 100644 --- a/FICS/comproc.c +++ b/FICS/comproc.c @@ -45,6 +45,8 @@ array index read/write. Markus Uhlin 25/07/21 com_who: fixed multiplication result converted to larger type. + Markus Uhlin 25/07/24 Fixed use of potentially + dangerous functions. */ #include "stdinclude.h" @@ -53,6 +55,7 @@ #include <sys/resource.h> #include <err.h> +#include <errno.h> #include "board.h" #include "command.h" @@ -389,11 +392,18 @@ com_stats_rating(char *hdr, statistics *stats, char *dest, const size_t dsize) stats->num); if (stats->whenbest) { + struct tm res = {0}; + snprintf(tmp, sizeof tmp, " %d", stats->best); strlcat(dest, tmp, dsize); - strftime(tmp, sizeof tmp, " (%d-%b-%y)", - localtime((time_t *) &stats->whenbest)); - strlcat(dest, tmp, dsize); + + errno = 0; + + if (localtime_r(&stats->whenbest, &res) != NULL) { + if (strftime(tmp, sizeof tmp, " (%d-%b-%y)", &res) != 0) + strlcat(dest, tmp, dsize); + } else + warn("%s: localtime_r", __func__); } if (strlcat(dest, "\n", dsize) >= dsize) { @@ -583,9 +593,14 @@ com_stats(int p, param_list param) if (connected && parray[p1].registered && (p == p1 || parray[p].adminLevel > 0)) { - char *timeToStr = ctime((time_t *) &parray[p1].timeOfReg); + char timeToStr[30] = { '\0' }; + + errno = 0; + + if (ctime_r(&parray[p1].timeOfReg, timeToStr) == NULL) + warn("%s: ctime_r", __func__); + timeToStr[strcspn(timeToStr, "\n")] = '\0'; - timeToStr[strlen(timeToStr) - 1] = '\0'; pprintf(p, "\n"); onTime = ((time(NULL) - parray[p1].logon_time) + |