]> xenbits.xensource.com Git - xen.git/commitdiff
libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
authorJennifer Herbert <Jennifer.Herbert@citrix.com>
Tue, 7 Jul 2015 16:38:59 +0000 (16:38 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 8 Jul 2015 09:51:56 +0000 (10:51 +0100)
Unlikely that it may seem localtime_r could fail, which would result in a
null pointer dereference.  In this case, it shoud log the errno, (instead of
the date/time), and and continue its logging, as this is still useful.

Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xtl_logger_stdio.c

index d8646e08b90eeb2264513108cb7c7b22ba707716..b28ef730a30db3bf9a97059f9d7dcc89f5c52187 100644 (file)
@@ -61,10 +61,13 @@ static void stdiostream_vmessage(xentoollog_logger *logger_in,
         struct tm lt_buf;
         time_t now = time(0);
         struct tm *lt= localtime_r(&now, &lt_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]);
+        else
+            fprintf(lg->f, "[localtime_r failed: %d] ", errno);
     }
     if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
         fprintf(lg->f, "[%lu] ", (unsigned long)getpid());