libdlog pipe: fix correctness checks 65/194865/2
authorMichal Bloch <m.bloch@samsung.com>
Fri, 7 Dec 2018 12:21:22 +0000 (13:21 +0100)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 12 Dec 2018 08:26:20 +0000 (08:26 +0000)
 * rejects on negative buffer ID (no longer crashes)
 * rejects relative socket paths
 * accepts maximal payloads

Change-Id: I7344cf4d47eb65c98a65a01ad4ada38ca9c9b5fd
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlog/log_pipe.c

index 9d96245..a036c5c 100644 (file)
@@ -118,10 +118,11 @@ static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *t
                tag = ""; // LCOV_EXCL_LINE
 
        if (log_id >= LOG_ID_MAX ||
+           log_id < 0 ||
            prio < DLOG_VERBOSE ||
            prio >= DLOG_PRIO_MAX ||
            !msg ||
-           1 /* priority */ + strlen(tag) + 1 /* NULL delimiter */ + strlen(msg) + 1 /* NULL terminator */ >= LOG_MAX_PAYLOAD_SIZE)
+           1 /* priority */ + strlen(tag) + 1 /* NULL delimiter */ + strlen(msg) + 1 /* NULL terminator */ > LOG_MAX_PAYLOAD_SIZE)
                return DLOG_ERROR_INVALID_PARAMETER;
 
        create_pipe_message(buf, prio, tag, msg);
@@ -174,6 +175,11 @@ void __dlog_init_pipe(const struct log_config *conf)
                        return; // LCOV_EXCL_LINE
                }
 
+               if (conf_val[0] != '/') {
+                       syslog_critical_failure("DLOG CRITICAL FAILURE: path \"%s\% from \"%s\" is not absolute!\n", conf_val, conf_key);
+                       return;
+               }
+
                const size_t pathlen = strlen(conf_val);
                static const size_t MAX_PIPE_PATH = sizeof ((struct sockaddr_un *)NULL)->sun_path;
                if (strlen(conf_val) >= MAX_PIPE_PATH) {