kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16-epplets.git/commit/?id=284a5039f9381016a6b6d0cb9b6d4eea9177159f

commit 284a5039f9381016a6b6d0cb9b6d4eea9177159f
Author: Kim Woelders <k...@woelders.dk>
Date:   Sun Aug 29 07:30:46 2021 +0200

    E-Pinger: Fix potential buffer overrun
---
 epplets/E-Pinger.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/epplets/E-Pinger.c b/epplets/E-Pinger.c
index c143387..0ed7d34 100644
--- a/epplets/E-Pinger.c
+++ b/epplets/E-Pinger.c
@@ -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)
      {

-- 


Reply via email to