All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
@ 2015-07-07 15:48 Jennifer Herbert
  2015-07-07 15:51 ` Andrew Cooper
  2015-07-07 16:04 ` Ian Jackson
  0 siblings, 2 replies; 6+ messages in thread
From: Jennifer Herbert @ 2015-07-07 15:48 UTC (permalink / raw)
  To: xen-devel
  Cc: wei.liu2, ian.jackson, ian.campbell, Jennifer Herbert,
	stefano.stabellini

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>
---
 tools/libxc/xtl_logger_stdio.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c
index d8646e0..5569c50 100644
--- a/tools/libxc/xtl_logger_stdio.c
+++ b/tools/libxc/xtl_logger_stdio.c
@@ -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());
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
  2015-07-07 15:48 [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage() Jennifer Herbert
@ 2015-07-07 15:51 ` Andrew Cooper
  2015-07-07 16:05   ` Ian Jackson
  2015-07-07 16:08   ` Jennifer Herbert
  2015-07-07 16:04 ` Ian Jackson
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Cooper @ 2015-07-07 15:51 UTC (permalink / raw)
  To: Jennifer Herbert, xen-devel
  Cc: ian.jackson, wei.liu2, ian.campbell, stefano.stabellini

On 07/07/15 16:48, Jennifer Herbert wrote:
> 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>
> ---
>  tools/libxc/xtl_logger_stdio.c |   11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c
> index d8646e0..5569c50 100644
> --- a/tools/libxc/xtl_logger_stdio.c
> +++ b/tools/libxc/xtl_logger_stdio.c
> @@ -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);

lg->f ?

~Andrew

>      }
>      if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
>          fprintf(lg->f, "[%lu] ", (unsigned long)getpid());

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
  2015-07-07 15:48 [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage() Jennifer Herbert
  2015-07-07 15:51 ` Andrew Cooper
@ 2015-07-07 16:04 ` Ian Jackson
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Jackson @ 2015-07-07 16:04 UTC (permalink / raw)
  To: Jennifer Herbert; +Cc: stefano.stabellini, wei.liu2, ian.campbell, xen-devel

Jennifer Herbert writes ("[PATCH V2] 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.

Thanks,

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
  2015-07-07 15:51 ` Andrew Cooper
@ 2015-07-07 16:05   ` Ian Jackson
  2015-07-07 16:13     ` Jennifer Herbert
  2015-07-07 16:08   ` Jennifer Herbert
  1 sibling, 1 reply; 6+ messages in thread
From: Ian Jackson @ 2015-07-07 16:05 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: wei.liu2, stefano.stabellini, Jennifer Herbert, ian.campbell,
	xen-devel

Andrew Cooper writes ("Re: [Xen-devel] [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):
> On 07/07/15 16:48, Jennifer Herbert wrote:
> > +        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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
  2015-07-07 15:51 ` Andrew Cooper
  2015-07-07 16:05   ` Ian Jackson
@ 2015-07-07 16:08   ` Jennifer Herbert
  1 sibling, 0 replies; 6+ messages in thread
From: Jennifer Herbert @ 2015-07-07 16:08 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel
  Cc: ian.jackson, wei.liu2, ian.campbell, stefano.stabellini

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

On 07/07/15 16:51, Andrew Cooper wrote:
> On 07/07/15 16:48, Jennifer Herbert wrote:
>> 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>
>> ---
>>   tools/libxc/xtl_logger_stdio.c |   11 +++++++----
>>   1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c
>> index d8646e0..5569c50 100644
>> --- a/tools/libxc/xtl_logger_stdio.c
>> +++ b/tools/libxc/xtl_logger_stdio.c
>> @@ -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);
> lg->f ?
>
> ~Andrew
>
>>       }
>>       if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
>>           fprintf(lg->f, "[%lu] ", (unsigned long)getpid());

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()
  2015-07-07 16:05   ` Ian Jackson
@ 2015-07-07 16:13     ` Jennifer Herbert
  0 siblings, 0 replies; 6+ messages in thread
From: Jennifer Herbert @ 2015-07-07 16:13 UTC (permalink / raw)
  To: Ian Jackson, Andrew Cooper
  Cc: stefano.stabellini, wei.liu2, ian.campbell, xen-devel

On 07/07/15 17:05, Ian Jackson wrote:
> Andrew Cooper writes ("Re: [Xen-devel] [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage()"):
>> On 07/07/15 16:48, Jennifer Herbert wrote:
>>> +        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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-07 16:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-07 15:48 [PATCH V2] libxc: Prevent NULL pointer dereference in stdiostream_vmessage() Jennifer Herbert
2015-07-07 15:51 ` Andrew Cooper
2015-07-07 16:05   ` Ian Jackson
2015-07-07 16:13     ` Jennifer Herbert
2015-07-07 16:08   ` Jennifer Herbert
2015-07-07 16:04 ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.