Skip to contentSkip to conversation

libxc: Prevent NULL pointer dereference in stdiostream_vmessage()

PATCH Superseded Jennifer Herbert 3 participants 6 messages Jul 7, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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
index d8646e0..5569c50 100644
@@ -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());
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 18 lines · Jennifer Herbert

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 +0 -1
index d8646e0..5569c50 100644
@@ -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 ",

tools/libxc/xtl_logger_stdio.c static void stdiostream_vmessage(xentoollog_logger *logger_in, · line 70

Quoted 10 lines
tools/libxc/xtl_logger_stdio.c +7 -3
-                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);

lg->f ?

~Andrew

Quoted 3 lines
tools/libxc/xtl_logger_stdio.c +0 -0
     }
     if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
         fprintf(lg->f, "[%lu] ", (unsigned long)getpid());
#2 lore raw

Andrew Cooper writes ("Re: [Xen-devel] [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):

Quoted 5 lines · Jennifer Herbert

tools/libxc/xtl_logger_stdio.c static void stdiostream_vmessage(xentoollog_logger *logger_in, · line 70

Quoted 2 lines
tools/libxc/xtl_logger_stdio.c +2 -0
+        else
+            fprintf(lg-f, "[localtime_r failed: %d] ", errno);

lg->f ?

I didn't spot this. I guess the patch wasn't build-tested...

Ian.

#3 lore raw
Quoted 7 lines · Ian Jackson

Andrew Cooper writes ("Re: [Xen-devel] [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):

Quoted 4 lines · Jennifer Herbert

tools/libxc/xtl_logger_stdio.c static void stdiostream_vmessage(xentoollog_logger *logger_in, · line 70

Quoted 2 lines
tools/libxc/xtl_logger_stdio.c +2 -0
+        else
+            fprintf(lg-f, "[localtime_r failed: %d] ", errno);

lg->f ?

I didn't spot this. I guess the patch wasn't build-tested...

Not sure what happened there - something was built tested, but I presumably without this patch. Sorry about that.

-jenny

#4 lore raw
In reply to Andrew Cooper

I guess I didn't build what I thought I built.
V3 coming up

Quoted 36 lines · Andrew Cooper
Quoted 18 lines · Jennifer Herbert

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 +0 -1
index d8646e0..5569c50 100644
@@ -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 ",

tools/libxc/xtl_logger_stdio.c static void stdiostream_vmessage(xentoollog_logger *logger_in, · line 70

Quoted 10 lines
tools/libxc/xtl_logger_stdio.c +7 -3
-                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);

lg->f ?

~Andrew

Quoted 3 lines
tools/libxc/xtl_logger_stdio.c +0 -0
      }
      if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
          fprintf(lg->f, "[%lu] ", (unsigned long)getpid());
Acked-by on v2 1/1
#5 lore raw
In reply to Jennifer Herbert

Jennifer Herbert writes ("[PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):

Quoted 3 lines

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.

Thanks,