Fix: lttng: uninitialized pointer free'd when no sessiond is present
[lttng-tools.git] / src / common / condition.c
index 0b184422a69bf0b3f3b36f877d0522b1ce8d8ee7..076f0627cb48387abfe217bf6f5d77e200ad2074 100644 (file)
@@ -1,22 +1,14 @@
 /*
- * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2017 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/condition/condition-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
+#include <lttng/condition/session-consumed-size-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
 #include <common/macros.h>
 #include <common/error.h>
 #include <common/dynamic-buffer.h>
@@ -62,11 +54,11 @@ end:
 }
 
 LTTNG_HIDDEN
-ssize_t lttng_condition_serialize(const struct lttng_condition *condition,
-               char *buf)
+int lttng_condition_serialize(const struct lttng_condition *condition,
+               struct lttng_dynamic_buffer *buf)
 {
-       ssize_t ret, condition_size;
-       struct lttng_condition_comm condition_comm;
+       int ret;
+       struct lttng_condition_comm condition_comm = { 0 };
 
        if (!condition) {
                ret = -1;
@@ -74,18 +66,17 @@ ssize_t lttng_condition_serialize(const struct lttng_condition *condition,
        }
 
        condition_comm.condition_type = (int8_t) condition->type;
-       ret = sizeof(struct lttng_condition_comm);
-       if (buf) {
-               memcpy(buf, &condition_comm, ret);
-               buf += ret;
+
+       ret = lttng_dynamic_buffer_append(buf, &condition_comm,
+                       sizeof(condition_comm));
+       if (ret) {
+               goto end;
        }
 
-       condition_size = condition->serialize(condition, buf);
-       if (condition_size < 0) {
-               ret = condition_size;
+       ret = condition->serialize(condition, buf);
+       if (ret) {
                goto end;
        }
-       ret += condition_size;
 end:
        return ret;
 }
@@ -104,6 +95,11 @@ bool lttng_condition_is_equal(const struct lttng_condition *a,
                goto end;
        }
 
+       if (a == b) {
+               is_equal = true;
+               goto end;
+       }
+
        is_equal = a->equal ? a->equal(a, b) : true;
 end:
        return is_equal;
@@ -134,6 +130,15 @@ ssize_t lttng_condition_create_from_buffer(
        case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
                create_from_buffer = lttng_condition_buffer_usage_high_create_from_buffer;
                break;
+       case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
+               create_from_buffer = lttng_condition_session_consumed_size_create_from_buffer;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+               create_from_buffer = lttng_condition_session_rotation_ongoing_create_from_buffer;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               create_from_buffer = lttng_condition_session_rotation_completed_create_from_buffer;
+               break;
        default:
                ERR("Attempted to create condition of unknown type (%i)",
                                (int) condition_comm->condition_type);
This page took 0.025597 seconds and 5 git commands to generate.