From 2f571d6fcdc6603de2b68eef27214c360a1dac5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 23 Jun 2020 18:06:53 -0400 Subject: [PATCH] Fix: evaluation: dereference before NULL check in create_from_payload MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit An evaluation payload view is created from the view passed to lttng_evaluation_create_from_payload. Since a view contains a const copy of the _fds array, it must be initialized as the declaration site. However, src_view is checked for NULL after the initalization. Coverity rightfully warns that: 1429799 Dereference before null check There may be a null pointer dereference, or else the comparison against null is unnecessary. In lttng_evaluation_create_from_payload: All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476) This is not reachable right now, but it is fixed to silence the warning and prevent future mistakes. Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: I3ceace4117ff54265b1f0cf6a4c638aec95f2879 --- src/common/evaluation.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/evaluation.c b/src/common/evaluation.c index cb379168e..e936bdd91 100644 --- a/src/common/evaluation.c +++ b/src/common/evaluation.c @@ -53,9 +53,10 @@ ssize_t lttng_evaluation_create_from_payload( { ssize_t ret, evaluation_size = 0; const struct lttng_evaluation_comm *evaluation_comm; - struct lttng_payload_view evaluation_view = - lttng_payload_view_from_view( - src_view, sizeof(*evaluation_comm), -1); + struct lttng_payload_view evaluation_view = src_view ? + lttng_payload_view_from_view(src_view, + sizeof(*evaluation_comm), -1) : + (typeof(evaluation_view)) {}; if (!src_view || !evaluation) { ret = -1; -- 2.34.1