Fix a null dereference. 26/305526/1 accepted/tizen_unified_toolchain accepted/tizen/unified/20240207.034837 accepted/tizen/unified/toolchain/20240311.065543 accepted/tizen/unified/x/20240205.160151
authorMichal Bloch <m.bloch@samsung.com>
Fri, 2 Feb 2024 16:57:48 +0000 (17:57 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 2 Feb 2024 18:31:27 +0000 (19:31 +0100)
Change-Id: I13168087ef460e74c203ab0f0311b91f6f242200

src/libdlog/log.c
src/tests/libdlog_base_neg.c

index 7119d49..3406d13 100644 (file)
@@ -374,18 +374,12 @@ static void __dlog_fatal_assert(int prio)
  * @brief Check log validity
  * @details Checks whether the log is valid and eligible for printing
  * @param[in] log_id The target buffer ID
- * @param[in] prio The log's priority
- * @param[in] tag The log's tag
  * @param[in] only_core Whether non-core buffers are rejected
  * @return DLOG_ERROR_NONE on success, else an error code.
  * @retval DLOG_ERROR_INVALID_PARAMETER Invalid parameter
  */
-static int dlog_check_validity(log_id_t log_id, int prio, const char *tag, bool only_core)
+static int dlog_check_validity(log_id_t log_id, bool only_core)
 {
-       (void) prio;
-       if (!tag)
-               return DLOG_ERROR_INVALID_PARAMETER;
-
        if (!is_buffer_valid(log_id))
                return DLOG_ERROR_INVALID_PARAMETER;
 
@@ -494,6 +488,9 @@ static int __write_to_log_critical_section(log_id_t log_id, int prio, const char
 
 static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap, bool check_should_log, bool secure_log)
 {
+       if (!fmt || !tag)
+               return DLOG_ERROR_INVALID_PARAMETER;
+
        /* Write down the log first, before all other checks. This
         * is because validity checks may involve syscalls, which
         * could overwrite `errno` and ruin the `%m` specifier if
@@ -505,8 +502,7 @@ static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char
        else if (len >= sizeof buf)
                len = sizeof buf - 1;
 
-
-       int ret = dlog_check_validity(log_id, prio, tag, check_should_log);
+       int ret = dlog_check_validity(log_id, check_should_log);
        if (ret < 0)
                return ret;
 
index 25ea5ae..7a1f3f9 100644 (file)
@@ -48,9 +48,11 @@ int main(void)
 
        assert(__dlog_print((log_id_t) -1, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_INVALID_PARAMETER);
        assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, NULL , "msg") == DLOG_ERROR_INVALID_PARAMETER);
+       assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, "tag", NULL) == DLOG_ERROR_INVALID_PARAMETER);
 
        assert(__dlog_sec_print((log_id_t) -1, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_INVALID_PARAMETER);
        assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_ERROR, NULL , "msg") == DLOG_ERROR_INVALID_PARAMETER);
+       assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_ERROR, "tag", NULL) == DLOG_ERROR_INVALID_PARAMETER);
 
        limiter_ret = (struct pass_log_result) { .decision = DECISION_ALLOWED };
        __dlog_fini();