Fix: lttng: uninitialized pointer free'd when no sessiond is present
[lttng-tools.git] / src / lib / lttng-ctl / destruction-handle.c
index b6a70bac6803cf852933ffb87d25398498a86b57..c6bb388ebcab793a97badf56e283c832f84b5378 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License, version 2.1 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <lttng/destruction-handle.h>
@@ -243,6 +233,11 @@ lttng_destruction_handle_wait_for_completion(
        const bool has_timeout = timeout_ms > 0;
         struct timespec initial_time;
 
+       if (!handle) {
+               status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
+               goto end;
+       }
+
         if (handle->communication.state == COMMUNICATION_STATE_ERROR) {
                status = LTTNG_DESTRUCTION_HANDLE_STATUS_ERROR;
                goto end;
@@ -329,6 +324,11 @@ lttng_destruction_handle_get_rotation_state(
        enum lttng_destruction_handle_status status =
                        LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
 
+       if (!handle || !rotation_state) {
+               status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
+               goto end;
+       }
+
        if (!handle->rotation_state.is_set) {
                status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
                goto end;
@@ -346,6 +346,11 @@ lttng_destruction_handle_get_archive_location(
        enum lttng_destruction_handle_status status =
                        LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
 
+       if (!handle || !location) {
+               status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
+               goto end;
+       }
+
        if (!handle->location) {
                status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
                goto end;
@@ -363,6 +368,11 @@ lttng_destruction_handle_get_result(
        enum lttng_destruction_handle_status status =
                        LTTNG_DESTRUCTION_HANDLE_STATUS_OK;
 
+       if (!handle || !result) {
+               status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
+               goto end;
+       }
+
        if (!handle->destruction_return_code.is_set) {
                status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID;
                goto end;
@@ -384,6 +394,11 @@ enum lttng_error_code lttng_destroy_session_ext(const char *session_name,
        int sessiond_socket = -1;
        struct lttng_destruction_handle *handle = NULL;
 
+       if (!session_name || !_handle) {
+               ret_code = LTTNG_ERR_INVALID;
+               goto error;
+       }
+
        ret = lttng_strncpy(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
        if (ret) {
@@ -420,7 +435,9 @@ enum lttng_error_code lttng_destroy_session_ext(const char *session_name,
 error:
        if (sessiond_socket >= 0) {
                ret = close(sessiond_socket);
-               PERROR("Failed to close the LTTng session daemon connection socket");
+               if (ret < 0) {
+                       PERROR("Failed to close the LTTng session daemon connection socket");
+               }
        }
        if (handle) {
                lttng_destruction_handle_destroy(handle);
This page took 0.027408 seconds and 5 git commands to generate.