Skip to content

Commit 9426d52

Browse files
Change localtime() -> localtime_r()
Found by: Arno Patch by: michaelortmann
1 parent 2f7801c commit 9426d52

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

src/main.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int nested_debug = 0;
238238
static void write_debug()
239239
{
240240
int x;
241-
char s[25];
241+
char s[26];
242242

243243
if (nested_debug) {
244244
/* Yoicks, if we have this there's serious trouble!
@@ -247,7 +247,7 @@ static void write_debug()
247247
x = creat("DEBUG.DEBUG", 0644);
248248
if (x >= 0) {
249249
setsock(x, SOCK_NONSOCK);
250-
strlcpy(s, ctime(&now), sizeof s);
250+
ctime_r(&now, s);
251251
dprintf(-x, "Debug (%s) written %s\n"
252252
"Please report problem to https://github.com/eggheads/eggdrop/issues\n"
253253
"Check doc/BUG-REPORT on how to do so.", ver, s);
@@ -275,8 +275,8 @@ static void write_debug()
275275
if (x < 0) {
276276
putlog(LOG_MISC, "*", "* Failed to write DEBUG");
277277
} else {
278-
strlcpy(s, ctime(&now), sizeof s);
279-
dprintf(-x, "Debug (%s) written %s\n", ver, s);
278+
ctime_r(&now, s);
279+
dprintf(-x, "Debug (%s) written %s", ver, s);
280280
#ifdef EGG_PATCH
281281
dprintf(-x, "Patch level: %s\n", EGG_PATCH);
282282
#else
@@ -575,7 +575,7 @@ static void core_secondly()
575575
}
576576
nowmins = now / 60;
577577
if (nowmins > lastmin) {
578-
memcpy(&nowtm, localtime(&now), sizeof(struct tm));
578+
localtime_r(&now, &nowtm);
579579
i = 0;
580580
/* Once a minute */
581581
++lastmin;
@@ -599,10 +599,11 @@ static void core_secondly()
599599
check_botnet_pings();
600600

601601
if (!miltime) { /* At midnight */
602-
char s[25];
602+
char s[26];
603603
int j;
604604

605-
strlcpy(s, ctime(&now), sizeof s);
605+
ctime_r(&now, s);
606+
s[24] = 0;
606607
if (quiet_save < 3)
607608
putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
608609
call_hook(HOOK_BACKUP);
@@ -946,7 +947,7 @@ static void init_random(void) {
946947
int main(int arg_c, char **arg_v)
947948
{
948949
int i, j, xx;
949-
char s[25];
950+
char s[26];
950951
FILE *f;
951952
struct sigaction sv;
952953
struct chanset_t *chan;
@@ -1068,8 +1069,8 @@ int main(int arg_c, char **arg_v)
10681069
dns_thread_head = nmalloc(sizeof(struct dns_thread_node));
10691070
dns_thread_head->next = NULL;
10701071
#endif
1071-
strlcpy(s, ctime(&now), sizeof s);
1072-
memmove(&s[11], &s[20], strlen(&s[20]) + 1);
1072+
ctime_r(&now, s);
1073+
s[24] = 0;
10731074
putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s);
10741075
chanprog();
10751076
if (!encrypt_pass2 && !encrypt_pass) {

src/misc.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,20 @@ void putlog (int type, char *chname, const char *format, ...)
517517
va_list va;
518518
time_t now2 = time(NULL);
519519
static time_t now2_last = 0; /* cache expensive localtime() */
520-
static struct tm *t;
520+
static struct tm t;
521521

522522
if (now2 != now2_last) {
523523
now2_last = now2;
524-
t = localtime(&now2);
524+
localtime_r(&now2, &t);
525525
}
526526

527527
va_start(va, format);
528528

529529
/* Create the timestamp */
530530
if (shtime) {
531-
strftime(stamp, sizeof(stamp) - 2, log_ts, t);
532-
strcat(stamp, " ");
533-
tsl = strlen(stamp);
531+
tsl = strftime(stamp, sizeof(stamp) - 2, log_ts, &t);
532+
stamp[tsl++] = ' ';
533+
stamp[tsl] = 0;
534534
}
535535
else
536536
*stamp = '\0';
@@ -544,9 +544,9 @@ void putlog (int type, char *chname, const char *format, ...)
544544
out[LOGLINEMAX - tsl] = 0;
545545
if (keep_all_logs) {
546546
if (!logfile_suffix[0])
547-
strftime(ct, 12, ".%d%b%Y", t);
547+
strftime(ct, 12, ".%d%b%Y", &t);
548548
else {
549-
strftime(ct, 80, logfile_suffix, t);
549+
strftime(ct, 80, logfile_suffix, &t);
550550
ct[80] = 0;
551551
s2 = ct;
552552
/* replace spaces by underscores */

src/mod/channels.mod/channels.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static char *convert_element(char *src, char *dst)
385385
static void write_channels()
386386
{
387387
FILE *f;
388-
char s[sizeof chanfile + 4], w[1024], w2[1024], name[163];
388+
char s[sizeof chanfile + 4], s1[26], w[1024], w2[1024], name[163];
389389
char need1[242], need2[242], need3[242], need4[242], need5[242];
390390
struct chanset_t *chan;
391391
struct udef_struct *ul;
@@ -401,8 +401,9 @@ static void write_channels()
401401
}
402402
if (!quiet_save)
403403
putlog(LOG_MISC, "*", "Writing channel file...");
404-
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s\n",
405-
botnetnick, ver, ctime(&now));
404+
ctime_r(&now, s1);
405+
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s",
406+
botnetnick, ver, s1);
406407
for (chan = chanset; chan; chan = chan->next) {
407408
convert_element(chan->dname, name);
408409
get_mode_protect(chan, w);

src/mod/ctcp.mod/ctcp.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ static int ctcp_CLIENTINFO(char *nick, char *uhosr, char *handle,
128128
static int ctcp_TIME(char *nick, char *uhost, char *handle, char *object,
129129
char *keyword, char *text)
130130
{
131-
char tms[25];
131+
char s[26];
132132

133133
if (ctcp_mode == 1)
134134
return 1;
135-
strlcpy(tms, ctime(&now), sizeof tms);
136-
simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, tms);
135+
ctime_r(&now, s);
136+
s[24] = 0;
137+
simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, s);
137138
return 1;
138139
}
139140

src/mod/uptime.mod/uptime.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ static int uptime_expmem()
9797
static void uptime_report(int idx, int details)
9898
{
9999
int delta_seconds;
100-
char *next_update_at;
100+
char next_update_at[26];
101101

102102
if (details) {
103103
delta_seconds = (int) (next_update - time(NULL));
104-
next_update_at = ctime(&next_update);
105-
next_update_at[strlen(next_update_at) - 1] = 0;
106-
104+
ctime_r(&next_update, next_update_at);
105+
next_update_at[24] = 0;
107106
dprintf(idx, " %d uptime packet%s sent\n", uptimecount,
108107
(uptimecount != 1) ? "s" : "");
109108
dprintf(idx, " Approximately %-.2f hours until next update "

src/tclmisc.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,13 @@ static int tcl_unixtime STDVAR
405405
static int tcl_ctime STDVAR
406406
{
407407
time_t tt;
408-
char s[25];
408+
char s[26];
409409

410410
BADARGS(2, 2, " unixtime");
411411

412412
tt = (time_t) atol(argv[1]);
413-
strlcpy(s, ctime(&tt), sizeof s);
413+
ctime_r(&tt, s);
414+
s[24] = 0;
414415
Tcl_AppendResult(irp, s, NULL);
415416
return TCL_OK;
416417
}

src/userrec.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,7 @@ void write_userfile(int idx)
637637
{
638638
FILE *f;
639639
char new_userfile[(sizeof userfile) + 4]; /* 4 = strlen("~new") */
640-
char s1[81];
641-
time_t tt;
640+
char s[26];
642641
struct userrec *u;
643642
int ok;
644643

@@ -657,9 +656,8 @@ void write_userfile(int idx)
657656
putlog(LOG_MISC, "*", "%s", USERF_WRITING);
658657

659658
sort_userlist();
660-
tt = now;
661-
strlcpy(s1, ctime(&tt), sizeof s1);
662-
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s1);
659+
ctime_r(&now, s);
660+
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s);
663661
ok = 1;
664662
/* Add all users except the -t user */
665663
for (u = userlist; u && ok; u = u->next)

0 commit comments

Comments
 (0)