libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
PATCH v3 1/1 libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
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.
--- tools/libxc/xtl_logger_stdio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/libxc/xtl_logger_stdio.c +7 -4
@@ -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, <_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 ());
Signature · 1 line
1.7.10.4
Jennifer Herbert writes ("[PATCH V3] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):
Quoted 5 lines
Unlikely that it may seem
localtime_rcould 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 <[email protected]>
Ian Campbell
AppliedQuoted 8 lines · Ian Jackson
Jennifer Herbert writes ("[PATCH V3] libxc: Prevent NULL pointer dereference in
stdiostream_vmessage()"):Quoted 5 lines
Unlikely that it may seem
localtime_rcould 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 <[email protected]>Acked-by Ian Jackson <[email protected]>
Applied.