return TIZEN_ERROR_NONE;
}
+bool verfiy_entry(const dlogutil_entry_s *entry)
+{
+ assert(entry);
+
+ const int payload_len = entry->len - (int) sizeof(dlogutil_entry_s);
+
+ /* This just checks if the entry is big enough to contain both the delimiter
+ * between the tag and the message, and the ending '\0'. */
+ if (payload_len < 2)
+ return false;
+
+ /* This condition is slightly weird.
+ * The point is that the payload of the entry cannot be too big.
+ * We have the limit of the payload introduced in the logger backend
+ * which had been then adopted by the pipe backend, and which we can check
+ * against. However, while this is the limit enforced by the pipe backend,
+ * the logger backend actually enforces a limit that is one character less.
+ * This makes sense in the context of the logger backend,
+ * as it simply expects (at least outside the stdout mode) some data;
+ * it doesn't really care about it's formatting. In our usage the data
+ * contains a single character for the priority, which is inside the struct
+ * in dlogutil_entry_s. However, this discreparency cannot be fixed easily,
+ * since the pipe backend actually can produce entries that use this limit
+ * completely. TODO: Is this inconsistency something we need to fix? */
+ if (payload_len > LOG_MAX_PAYLOAD_SIZE)
+ return false;
+
+ /* This makes sure that the message actually ends with a '\0'.
+ * This is important, since we return the data as a string. */
+ if (((const char *)entry)[entry->len - 1] != '\0')
+ return false;
+
+ return true;
+}
+
LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag)
{
CHECK_PARAM(entry);
CHECK_PARAM(tag);
- if (entry->len - (int) sizeof(dlogutil_entry_s) > LOG_MAX_PAYLOAD_SIZE
- || entry->len - (int) sizeof(dlogutil_entry_s) < 2
- || ((const char *)entry)[entry->len - 1] != '\0') {
+ if (!verfiy_entry(entry)) {
*tag = NULL;
return TIZEN_ERROR_NO_DATA;
}
CHECK_PARAM(entry);
CHECK_PARAM(msg);
- if (entry->len - (int) sizeof(dlogutil_entry_s) > LOG_MAX_PAYLOAD_SIZE
- || entry->len - (int) sizeof(dlogutil_entry_s) < 2
- || ((const char *)entry)[entry->len - 1] != '\0') {
+ if (!verfiy_entry(entry)) {
*msg = NULL;
return TIZEN_ERROR_NO_DATA;
}