From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jennifer Herbert Subject: [PATCH 7/7] libxc: Prevent NULL pointer dereference in stdiostream_vmessage() Date: Wed, 1 Jul 2015 17:37:12 +0000 Message-ID: <1435772232-39085-8-git-send-email-Jennifer.Herbert@citrix.com> References: <1435772232-39085-1-git-send-email-Jennifer.Herbert@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1435772232-39085-1-git-send-email-Jennifer.Herbert@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, Jennifer Herbert , stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Unlikely that it may seem localtime_r could fail, which would result in a null pointer dereference. In this case, one can simply just skip logging the date/time, and logging anything is more useful then nothing. Signed-off-by: Jennifer Herbert --- tools/libxc/xtl_logger_stdio.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c index d8646e0..74d66a5 100644 --- a/tools/libxc/xtl_logger_stdio.c +++ b/tools/libxc/xtl_logger_stdio.c @@ -61,10 +61,11 @@ static void stdiostream_vmessage(xentoollog_logger *logger_in, struct tm lt_buf; time_t now = time(0); struct tm *lt= localtime_r(&now, <_buf); - fprintf(lg->f, "%04d-%02d-%02d %02d:%02d:%02d %s ", - lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday, - lt->tm_hour, lt->tm_min, lt->tm_sec, - tzname[!!lt->tm_isdst]); + if (lt != NULL) + fprintf(lg->f, "%04d-%02d-%02d %02d:%02d:%02d %s ", + lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday, + lt->tm_hour, lt->tm_min, lt->tm_sec, + tzname[!!lt->tm_isdst]); } if (lg->flags & XTL_STDIOSTREAM_SHOW_PID) fprintf(lg->f, "[%lu] ", (unsigned long)getpid()); -- 1.7.10.4