Ticket #893: 0001-Prevents-that-uninitialized-data-is-formatted-and-pr.patch

File 0001-Prevents-that-uninitialized-data-is-formatted-and-pr.patch, 1.1 KB (added by gvranken, 4 years ago)
  • src/openvpn/otime.c

    From 6423186e8f332d6510646142d62e8b96880e4003 Mon Sep 17 00:00:00 2001
    From: g v <guido@guidovranken.nl>
    Date: Tue, 23 May 2017 17:06:25 +0200
    Subject: [PATCH] Prevents that uninitialized data is formatted and printed if
     gettimeofday() fails, and that no null pointer dereference will occur in
     vsnprintf (via buf_printf) if ctime() returns NULL
    
    ---
     src/openvpn/otime.c | 6 ++++--
     1 file changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c
    index 22abda0..e40b3a0 100644
    a b const char * 
    115115time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
    116116{
    117117    struct buffer out = alloc_buf_gc(64, gc);
    118     struct timeval tv;
     118    struct timeval tv = {0};
     119    char* timestr;
    119120
    120121    if (t)
    121122    {
    time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc) 
    128129    }
    129130
    130131    t = tv.tv_sec;
    131     buf_printf(&out, "%s", ctime(&t));
     132    timestr = ctime(&t);
     133    buf_printf(&out, "%s", timestr ? timestr : "(null)");
    132134    buf_rmtail(&out, '\n');
    133135
    134136    if (show_usec && tv.tv_usec)