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
*/
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;
}
/**
*/
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)