Improve log_buffer_get_* exceptional conditions 98/216398/1
authorMateusz Majewski <m.majewski2@samsung.com>
Thu, 24 Oct 2019 09:05:10 +0000 (11:05 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Thu, 24 Oct 2019 09:59:16 +0000 (11:59 +0200)
We now handle the case in which the struct lacks the ending '\0'.
This would mean that one could read past the end of the struct while
using the result.

Change-Id: Ie70ffd57181dd351ab94db27550b8f967235648f

src/shared/logprint.c

index f822aad..8782b6d 100644 (file)
@@ -539,10 +539,14 @@ int log_add_filter_tid(log_filter *p_filter, pthread_t tid)
  */
 const char* log_buffer_get_tag(const struct dlogutil_entry *entry)
 {
+       assert(entry);
+
        if (entry->len - (int) sizeof(struct dlogutil_entry) < 2)
                return NULL;
+       if (((const char *)entry)[entry->len - 1] != '\0')
+               return NULL;
 
-       return (char*)entry->msg;
+       return entry->msg;
 }
 
 /**
@@ -553,10 +557,14 @@ const char* log_buffer_get_tag(const struct dlogutil_entry *entry)
  */
 const char* log_buffer_get_message(const struct dlogutil_entry *entry)
 {
+       assert(entry);
+
        if (entry->len - (int) sizeof(struct dlogutil_entry) < 2)
                return NULL;
+       if (((const char *)entry)[entry->len - 1] != '\0')
+               return NULL;
 
-       return (char*)entry->msg + entry->tag_len + 1 /* NULL delimiter */;
+       return entry->msg + entry->tag_len + 1 /* NULL delimiter */;
 }
 
 enum dlogutil_sorting_order get_format_sorting(log_print_format format)