Fix: common: improper use of negative return
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 28 Jul 2020 14:19:30 +0000 (10:19 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 29 Jul 2020 16:36:04 +0000 (12:36 -0400)
From Coverity:

  CID 1431053 (#1 of 2): Improper use of negative value (NEGATIVE_RETURNS)
  5. negative_returns: fd_count is passed to a parameter that cannot be
     negative.

Solution
========

Check return value for fd_count and goto error if negative.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ibdb2f065f0ebe51efae9125630a17730386395ac

src/common/unix.c

index 50200242529992ce4b8244d4c4d897a28d35583d..2053343256a337fa25e5ab866a0950e488e5b02e 100644 (file)
@@ -453,6 +453,11 @@ ssize_t _lttcomm_send_payload_view_fds_unix_sock(int sock,
 
        lttng_dynamic_array_init(&raw_fds, sizeof(int), NULL);
 
 
        lttng_dynamic_array_init(&raw_fds, sizeof(int), NULL);
 
+       if (fd_count < 0) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
        /*
         * Prepare a contiguous array of file descriptors to send them.
         *
        /*
         * Prepare a contiguous array of file descriptors to send them.
         *
This page took 0.02525 seconds and 4 git commands to generate.