From: Jonathan Rajotte Date: Tue, 27 Apr 2021 01:07:08 +0000 (-0400) Subject: Fix: initialize temporary fd array element to -1 X-Git-Tag: v2.13.0-rc2~52 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9cf55c3c24472f49abac1957ae625190bb95b48d;p=lttng-tools.git Fix: initialize temporary fd array element to -1 These are FDs, an initialization value of zero is a valid FD number hence we must initialize the element to -1. This allows us to be more strict in `add_fds_to_payload` and assert that the passed FDs are actual FDs and not only bare zero-initialized element. Change-Id: Icc05d98d51906636362a67588d7c42b58cf33ded Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/unix.c b/src/common/unix.c index 0e6c329c0..623421cad 100644 --- a/src/common/unix.c +++ b/src/common/unix.c @@ -730,6 +730,8 @@ enum lttng_error_code add_fds_to_payload(struct lttng_dynamic_array *raw_fds, int *raw_fd = (int *) lttng_dynamic_array_get_element( raw_fds, i); + assert(*raw_fd != -1); + handle = fd_handle_create(*raw_fd); if (!handle) { ret_code = LTTNG_ERR_NOMEM; @@ -755,15 +757,19 @@ static ssize_t _lttcomm_recv_payload_fds_unix_sock(int sock, size_t nb_fd, struct lttng_payload *payload, bool blocking) { + int i = 0; enum lttng_error_code add_ret; ssize_t ret; + int default_value = -1; struct lttng_dynamic_array raw_fds; lttng_dynamic_array_init(&raw_fds, sizeof(int), close_raw_fd); - ret = lttng_dynamic_array_set_count(&raw_fds, nb_fd); - if (ret) { - ret = -LTTNG_ERR_NOMEM; - goto end; + + for (i = 0; i < nb_fd; i++) { + if (lttng_dynamic_array_add_element(&raw_fds, &default_value)) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } } if (blocking) {