E-Pinger: Fix potential buffer overrun

This commit is contained in:
Kim Woelders 2021-08-29 07:30:46 +02:00
parent 4f25ca8cd2
commit 284a5039f9
1 changed files with 4 additions and 7 deletions

View File

@ -46,7 +46,6 @@ static Epplet_gadget b_close, b_configure, b_help, p_log, pb_log, pb_log_small;
static Epplet_gadget tb_host, tb_pause;
static Window win, config_win;
static int log_entries, nchild;
static char buf[BUF_LEN];
static char *result, *new_result;
static char *host;
static int pinger_pause = 30;
@ -406,6 +405,7 @@ cb_timer(void *data __UNUSED__)
time_t now;
int nbyte;
char *s;
char tbuf[32], lbuf[128];
if ((nbyte = nb_read(0, new_result, BUF_LEN)) > 0)
{
@ -428,12 +428,9 @@ cb_timer(void *data __UNUSED__)
new_result = s;
now = time(NULL);
strncpy(buf, result, BUF_LEN - 1);
strftime(buf + nbyte + 1, BUF_LEN - nbyte - 1, "%H:%M %a %e %b %G",
localtime(&now));
*(buf + nbyte - 1) = ':';
*(buf + nbyte) = ' ';
add_log(result, buf);
strftime(tbuf, sizeof(tbuf), "%H:%M %a %e %b %G", localtime(&now));
snprintf(lbuf, sizeof(lbuf), "%s: %s", result, tbuf);
add_log(result, lbuf);
}
else if (new_ping)
{