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 * |
115 | 115 | time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc) |
116 | 116 | { |
117 | 117 | struct buffer out = alloc_buf_gc(64, gc); |
118 | | struct timeval tv; |
| 118 | struct timeval tv = {0}; |
| 119 | char* timestr; |
119 | 120 | |
120 | 121 | if (t) |
121 | 122 | { |
… |
… |
time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc) |
128 | 129 | } |
129 | 130 | |
130 | 131 | t = tv.tv_sec; |
131 | | buf_printf(&out, "%s", ctime(&t)); |
| 132 | timestr = ctime(&t); |
| 133 | buf_printf(&out, "%s", timestr ? timestr : "(null)"); |
132 | 134 | buf_rmtail(&out, '\n'); |
133 | 135 | |
134 | 136 | if (show_usec && tv.tv_usec) |