Fix the handling of over/undersized logs 91/265091/3
authorMichal Bloch <m.bloch@samsung.com>
Wed, 29 Sep 2021 18:48:34 +0000 (20:48 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 20 Oct 2021 11:18:33 +0000 (13:18 +0200)
Change-Id: Ibdc31f97dd0fd541b4f49f3eea89f8d5888f3737
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/log_buffer.c
src/shared/queued_entry.c
src/shared/queued_entry_timestamp.c

index f1a6e3c..46b1ab7 100644 (file)
@@ -41,7 +41,7 @@ static int service_writer_pipe(struct logger *server, struct writer *wr, struct
                struct pipe_logger_entry *const ple = (struct pipe_logger_entry *const)wr->buffer;
                while ((wr->readed >= sizeof(ple->len)) && (ple->len <= wr->readed)) {
                        const int payload_size = ple->len - sizeof *ple;
-                       if (payload_size < 0 || payload_size > LOG_MAX_PAYLOAD_SIZE)
+                       if (payload_size <= 0 || payload_size > LOG_MAX_PAYLOAD_SIZE)
                                return -EINVAL;
 
                        struct dlogutil_entry_with_msg lem;
index 4628eb8..fffd423 100644 (file)
@@ -323,6 +323,7 @@ void parse_pipe_message(struct pipe_logger_entry *ple, dlogutil_entry_s *le, siz
 {
        size_t payload_size = msg_size - sizeof *ple;
        assert(payload_size <= LOG_MAX_PAYLOAD_SIZE);
+       assert(payload_size > 0);
 
        SHARED_PROCESS_MESSAGE(ple);
 
index 16a64d1..09ae527 100644 (file)
@@ -181,7 +181,8 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_tag(const dlogutil_entry_s *entry,
        CHECK_PARAM(entry);
        CHECK_PARAM(tag);
 
-       if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
+       if (entry->len > LOG_MAX_PAYLOAD_SIZE
+       || entry->len - (int) sizeof(dlogutil_entry_s) < 2
        || ((const char *)entry)[entry->len - 1] != '\0') {
                *tag = NULL;
                return TIZEN_ERROR_NO_DATA;
@@ -196,7 +197,8 @@ LIBDLOGUTIL_EXPORT_API int dlogutil_entry_get_message(const dlogutil_entry_s *en
        CHECK_PARAM(entry);
        CHECK_PARAM(msg);
 
-       if (entry->len - (int) sizeof(dlogutil_entry_s) < 2
+       if (entry->len > LOG_MAX_PAYLOAD_SIZE
+       || entry->len - (int) sizeof(dlogutil_entry_s) < 2
        || ((const char *)entry)[entry->len - 1] != '\0') {
                *msg = NULL;
                return TIZEN_ERROR_NO_DATA;