assert(msg.cmd == HEALTH_CMD_CHECK);
- reply.ret_code = 0;
+ memset(&reply, 0, sizeof(reply));
for (i = 0; i < NR_HEALTH_CONSUMERD_TYPES; i++) {
/*
* health_check_state return 0 if thread is in
assert(msg.cmd == HEALTH_CMD_CHECK);
- reply.ret_code = 0;
+ memset(&reply, 0, sizeof(reply));
for (i = 0; i < NR_HEALTH_RELAYD_TYPES; i++) {
/*
* health_check_state return 0 if thread is in
health_code_update();
+ memset(&response, 0, sizeof(response));
+
rcu_read_lock();
session = session_find_by_id(conn->sessions_ht, session_id);
if (!session) {
health_code_update();
+ memset(&response, 0, sizeof(response));
+
if (!conn->viewer_session) {
DBG("Client trying to attach before creating a live viewer session");
response.status = htobe32(LTTNG_VIEWER_ATTACH_NO_SESSION);
}
health_code_update();
+ memset(&reply, 0, sizeof(reply));
+
rcu_read_lock();
stream = viewer_stream_find_by_id(be64toh(request.stream_id));
if (!stream || !stream->metadata_flag) {
DBG("Viewer create session received");
+ memset(&resp, 0, sizeof(resp));
resp.status = htobe32(LTTNG_VIEWER_CREATE_SESSION_OK);
conn->viewer_session = zmalloc(sizeof(*conn->viewer_session));
if (!conn->viewer_session) {
{
struct lttcomm_relayd_generic_reply reply;
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = htobe32(LTTNG_ERR_UNK);
(void) send_response(conn->sock, &reply, sizeof(reply));
}
stream->stream_handle);
end:
+ memset(&reply, 0, sizeof(reply));
reply.handle = htobe64(stream->stream_handle);
/* send the session id to the client or a negative return code on error */
if (ret < 0) {
end_unlock:
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
if (ret < 0) {
reply.ret_code = htobe32(LTTNG_ERR_UNK);
} else {
struct lttcomm_relayd_generic_reply reply;
int ret;
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = htobe32(LTTNG_ERR_UNK);
ret = conn->sock->ops->sendmsg(conn->sock, &reply,
sizeof(struct lttcomm_relayd_generic_reply), 0);
ret = htobe32(LTTNG_ERR_UNK);
}
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = ret;
ret = conn->sock->ops->sendmsg(conn->sock, &reply,
sizeof(struct lttcomm_relayd_generic_reply), 0);
goto end;
}
+ memset(&reply, 0, sizeof(reply));
reply.major = RELAYD_VERSION_COMM_MAJOR;
reply.minor = RELAYD_VERSION_COMM_MINOR;
end_unlock:
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = htobe32(ret);
ret = conn->sock->ops->sendmsg(conn->sock, &reply, sizeof(reply), 0);
if (ret < 0) {
}
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = htobe32(LTTNG_OK);
ret = conn->sock->ops->sendmsg(conn->sock, &reply, sizeof(reply), 0);
if (ret < 0) {
}
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
/* All good, send back reply. */
reply.ret_code = htobe32(LTTNG_OK);
}
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
/* All good, send back reply. */
reply.ret_code = htobe32(is_data_inflight);
end_rcu_unlock:
rcu_read_unlock();
+ memset(&reply, 0, sizeof(reply));
if (ret < 0) {
reply.ret_code = htobe32(LTTNG_ERR_UNK);
} else {
uatomic_set(&conn->session->new_streams, 1);
}
+ memset(&reply, 0, sizeof(reply));
reply.ret_code = htobe32(LTTNG_OK);
send_ret = conn->sock->ops->sendmsg(conn->sock, &reply, sizeof(reply), 0);
if (send_ret < 0) {
DBG2("Sending destroy relayd command to consumer sock %d", *sock->fd_ptr);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_DESTROY_RELAYD;
msg.u.destroy_relayd.net_seq_idx = consumer->net_seq_index;
assert(consumer);
assert(consumer_sock);
+ memset(&msg, 0, sizeof(msg));
/* Bail out if consumer is disabled */
if (!consumer->enabled) {
ret = LTTNG_OK;
assert(consumer);
- msg.cmd_type = LTTNG_CONSUMER_DATA_PENDING;
+ DBG3("Consumer data pending for id %" PRIu64, session_id);
+ memset(&msg, 0, sizeof(msg));
+ msg.cmd_type = LTTNG_CONSUMER_DATA_PENDING;
msg.u.data_pending.session_id = session_id;
- DBG3("Consumer data pending for id %" PRIu64, session_id);
-
/* Send command for each consumer */
rcu_read_lock();
cds_lfht_for_each_entry(consumer->socks->ht, &iter.iter, socket,
DBG2("Consumer flush channel key %" PRIu64, key);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_FLUSH_CHANNEL;
msg.u.flush_channel.key = key;
DBG2("Consumer close metadata channel key %" PRIu64, metadata_key);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_CLOSE_METADATA;
msg.u.close_metadata.key = metadata_key;
DBG2("Consumer setup metadata channel key %" PRIu64, metadata_key);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_SETUP_METADATA;
msg.u.setup_metadata.key = metadata_key;
DBG2("Consumer push metadata to consumer socket %d", *socket->fd_ptr);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_PUSH_METADATA;
msg.u.push_metadata.key = metadata_key;
msg.u.push_metadata.target_offset = target_offset;
assert(sock);
+ memset(&msg, 0, sizeof(msg));
msg.data_size = htobe64(data_size);
msg.cmd = htobe32(cmd);
msg.cmd_version = htobe32(cmd_version);
goto error_io;
}
+ memset(&msg, 0, sizeof(msg));
msg.loglevel = event->loglevel;
msg.loglevel_type = event->loglevel_type;
strncpy(msg.name, event->name, sizeof(msg.name));
goto error_io;
}
+ memset(&msg, 0, sizeof(msg));
strncpy(msg.name, event->name, sizeof(msg.name));
ret = send_payload(app->sock, &msg, sizeof(msg));
if (ret < 0) {
goto error_unlock;
}
- if (count >= nbmem) {
+ if (count + nb_ev > nbmem) {
/* In case the realloc fails, we free the memory */
- void *ptr;
-
- DBG2("Reallocating JUL event list from %zu to %zu entries", nbmem,
- 2 * nbmem);
- nbmem *= 2;
- ptr = realloc(tmp_events, nbmem * sizeof(*tmp_events));
- if (!ptr) {
+ struct lttng_event *new_tmp_events;
+ size_t new_nbmem;
+
+ new_nbmem = max_t(size_t, count + nb_ev, nbmem << 1);
+ DBG2("Reallocating JUL event list from %zu to %zu entries",
+ nbmem, new_nbmem);
+ new_tmp_events = realloc(tmp_events,
+ new_nbmem * sizeof(*new_tmp_events));
+ if (!new_tmp_events) {
PERROR("realloc JUL events");
ret = -ENOMEM;
free(jul_events);
goto error_unlock;
}
- tmp_events = ptr;
+ /* Zero the new memory */
+ memset(new_tmp_events + nbmem, 0,
+ (new_nbmem - nbmem) * sizeof(*new_tmp_events));
+ nbmem = new_nbmem;
+ tmp_events = new_tmp_events;
}
- memcpy(tmp_events + (count * sizeof(*tmp_events)), jul_events,
- nb_ev * sizeof(*tmp_events));
+ memcpy(tmp_events + count, jul_events,
+ nb_ev * sizeof(*tmp_events));
free(jul_events);
count += nb_ev;
}
}
} else {
/* Empty path. */
- pathname = "";
+ pathname = strdup("");
}
/* Prep channel message structure */
health_code_update();
error:
+ free(pathname);
return ret;
}
}
} else {
/* Empty path. */
- pathname = "";
+ pathname = strdup("");
}
/* Prep channel message structure */
health_code_update();
error:
+ free(pathname);
return ret;
}
DBG("Sending kernel consumer destroy channel key %d", channel->fd);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_DESTROY_CHANNEL;
msg.u.destroy_channel.key = channel->fd;
DBG("Sending kernel consumer destroy channel key %d", metadata->fd);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_DESTROY_CHANNEL;
msg.u.destroy_channel.key = metadata->fd;
*/
ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
{
- int fd, pos, ret;
+ int fd, ret;
char *event;
size_t nbmem, count = 0;
FILE *fp;
goto end;
}
- while (fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos) == 1) {
+ while (fscanf(fp, "event { name = %m[^;]; };\n", &event) == 1) {
if (count >= nbmem) {
struct lttng_event *new_elist;
+ size_t new_nbmem;
- DBG("Reallocating event list from %zu to %zu bytes", nbmem,
- nbmem * 2);
- /* Double the size */
- nbmem <<= 1;
- new_elist = realloc(elist, nbmem * sizeof(struct lttng_event));
+ new_nbmem = nbmem << 1;
+ DBG("Reallocating event list from %zu to %zu bytes",
+ nbmem, new_nbmem);
+ new_elist = realloc(elist, new_nbmem * sizeof(struct lttng_event));
if (new_elist == NULL) {
PERROR("realloc list events");
free(event);
count = -ENOMEM;
goto end;
}
+ /* Zero the new memory */
+ memset(new_elist + nbmem, 0,
+ (new_nbmem - nbmem) * sizeof(struct lttng_event));
+ nbmem = new_nbmem;
elist = new_elist;
}
strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
rcu_thread_online();
- reply.ret_code = 0;
+ memset(&reply, 0, sizeof(reply));
for (i = 0; i < NR_HEALTH_SESSIOND_TYPES; i++) {
/*
* health_check_state returns 0 if health is
#include <common/defaults.h>
#include "snapshot.h"
+#include "utils.h"
/*
* Return the atomically incremented value of next_output_id.
snapshot_output_destroy(output);
}
rcu_read_unlock();
+ ht_cleanup_push(obj->output_ht);
}
health_code_update();
if (count >= nbmem) {
/* In case the realloc fails, we free the memory */
- void *ptr;
-
- DBG2("Reallocating event list from %zu to %zu entries", nbmem,
- 2 * nbmem);
- nbmem *= 2;
- ptr = realloc(tmp_event, nbmem * sizeof(struct lttng_event));
- if (ptr == NULL) {
+ struct lttng_event *new_tmp_event;
+ size_t new_nbmem;
+
+ new_nbmem = nbmem << 1;
+ DBG2("Reallocating event list from %zu to %zu entries",
+ nbmem, new_nbmem);
+ new_tmp_event = realloc(tmp_event,
+ new_nbmem * sizeof(struct lttng_event));
+ if (new_tmp_event == NULL) {
PERROR("realloc ust app events");
free(tmp_event);
ret = -ENOMEM;
goto rcu_error;
}
- tmp_event = ptr;
+ /* Zero the new memory */
+ memset(new_tmp_event + nbmem, 0,
+ (new_nbmem - nbmem) * sizeof(struct lttng_event));
+ nbmem = new_nbmem;
+ tmp_event = new_tmp_event;
}
memcpy(tmp_event[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN);
tmp_event[count].loglevel = uiter.loglevel;
health_code_update();
if (count >= nbmem) {
/* In case the realloc fails, we free the memory */
- void *ptr;
-
- DBG2("Reallocating event field list from %zu to %zu entries", nbmem,
- 2 * nbmem);
- nbmem *= 2;
- ptr = realloc(tmp_event, nbmem * sizeof(struct lttng_event_field));
- if (ptr == NULL) {
+ struct lttng_event_field *new_tmp_event;
+ size_t new_nbmem;
+
+ new_nbmem = nbmem << 1;
+ DBG2("Reallocating event field list from %zu to %zu entries",
+ nbmem, new_nbmem);
+ new_tmp_event = realloc(tmp_event,
+ new_nbmem * sizeof(struct lttng_event_field));
+ if (new_tmp_event == NULL) {
PERROR("realloc ust app event fields");
free(tmp_event);
ret = -ENOMEM;
goto rcu_error;
}
- tmp_event = ptr;
+ /* Zero the new memory */
+ memset(new_tmp_event + nbmem, 0,
+ (new_nbmem - nbmem) * sizeof(struct lttng_event_field));
+ nbmem = new_nbmem;
+ tmp_event = new_tmp_event;
}
memcpy(tmp_event[count].field_name, uiter.field_name, LTTNG_UST_SYM_NAME_LEN);
assert(ua_chan);
assert(socket);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_GET_CHANNEL;
msg.u.get_channel.key = ua_chan->key;
assert(ua_chan);
assert(socket);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_CONSUMER_DESTROY_CHANNEL;
msg.u.destroy_channel.key = ua_chan->key;
DBG("PID registry not found for session id %" PRIu64,
request.session_id_per_pid);
+ memset(&msg, 0, sizeof(msg));
msg.cmd_type = LTTNG_ERR_UND;
(void) consumer_send_msg(socket, &msg);
/*
PERROR("realloc epoll add");
goto error;
}
+ if (new_size > events->alloc_size) {
+ /* Zero newly allocated memory */
+ memset(ptr + events->alloc_size, 0,
+ (new_size - events->alloc_size) * sizeof(*ptr));
+ }
events->events = ptr;
events->alloc_size = new_size;
goto error;
}
+ /*
+ * Zero struct epoll_event to ensure all representations of its
+ * union are zeroed.
+ */
+ memset(&ev, 0, sizeof(ev));
ev.events = req_events;
ev.data.fd = fd;
PERROR("realloc epoll add");
goto error;
}
+ if (new_size > array->alloc_size) {
+ /* Zero newly allocated memory */
+ memset(ptr + array->alloc_size, 0,
+ (new_size - array->alloc_size) * sizeof(*ptr));
+ }
array->events = ptr;
array->alloc_size = new_size;
{
int ret = 0;
char *tmp_data_ptr;
- unsigned int new_size;
+ unsigned int new_size, old_size;
assert(channel);
assert(channel->metadata_cache);
- new_size = max_t(unsigned int,
- channel->metadata_cache->cache_alloc_size + size,
- channel->metadata_cache->cache_alloc_size << 1);
+ old_size = channel->metadata_cache->cache_alloc_size;
+ new_size = max_t(unsigned int, old_size + size, old_size << 1);
DBG("Extending metadata cache to %u", new_size);
tmp_data_ptr = realloc(channel->metadata_cache->data, new_size);
if (!tmp_data_ptr) {
ret = -1;
goto end;
}
+ /* Zero newly allocated memory */
+ memset(tmp_data_ptr + old_size, 0, new_size - old_size);
channel->metadata_cache->data = tmp_data_ptr;
channel->metadata_cache->cache_alloc_size = new_size;
{
struct lttcomm_consumer_status_msg msg;
+ memset(&msg, 0, sizeof(msg));
msg.ret_code = ret_code;
return lttcomm_send_unix_sock(sock, &msg, sizeof(msg));
assert(sock >= 0);
+ memset(&msg, 0, sizeof(msg));
if (!channel) {
msg.ret_code = LTTCOMM_CONSUMERD_CHANNEL_FAIL;
} else {
goto alloc_error;
}
+ memset(&header, 0, sizeof(header));
header.cmd = htobe32(cmd);
header.data_size = htobe64(size);
/* Compat with relayd 2.1 */
if (rsock->minor == 1) {
+ memset(&msg, 0, sizeof(msg));
strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name));
strncpy(msg.pathname, pathname, sizeof(msg.pathname));
goto error;
}
} else {
+ memset(&msg_2_2, 0, sizeof(msg_2_2));
/* Compat with relayd 2.2+ */
strncpy(msg_2_2.channel_name, channel_name, sizeof(msg_2_2.channel_name));
strncpy(msg_2_2.pathname, pathname, sizeof(msg_2_2.pathname));
DBG("Relayd version check for major.minor %u.%u", rsock->major,
rsock->minor);
+ memset(&msg, 0, sizeof(msg));
/* Prepare network byte order before transmission. */
msg.major = htobe32(rsock->major);
msg.minor = htobe32(rsock->minor);
DBG("Relayd closing stream id %" PRIu64, stream_id);
+ memset(&msg, 0, sizeof(msg));
msg.stream_id = htobe64(stream_id);
msg.last_net_seq_num = htobe64(last_net_seq_num);
DBG("Relayd data pending for stream id %" PRIu64, stream_id);
+ memset(&msg, 0, sizeof(msg));
msg.stream_id = htobe64(stream_id);
msg.last_net_seq_num = htobe64(last_net_seq_num);
DBG("Relayd checking quiescent control state");
+ memset(&msg, 0, sizeof(msg));
msg.stream_id = htobe64(metadata_stream_id);
/* Send command */
DBG("Relayd begin data pending");
+ memset(&msg, 0, sizeof(msg));
msg.session_id = htobe64(id);
/* Send command */
DBG("Relayd end data pending");
+ memset(&msg, 0, sizeof(msg));
msg.session_id = htobe64(id);
/* Send command */
DBG("Relayd sending index for stream ID %" PRIu64, relay_stream_id);
+ memset(&msg, 0, sizeof(msg));
msg.relay_stream_id = htobe64(relay_stream_id);
msg.net_seq_num = htobe64(net_seq_num);
assert(channel);
assert(channel->metadata_cache);
+ memset(&request, 0, sizeof(request));
+
/* send the metadata request to sessiond */
switch (consumer_data.type) {
case LTTNG_CONSUMER64_UST:
goto error;
}
+ memset(&msg, 0, sizeof(msg));
msg.cmd = HEALTH_CMD_CHECK;
ret = lttcomm_send_unix_sock(sock, (void *)&msg, sizeof(msg));
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
lttng_ctl_copy_string(lsm.session.name, handle->session_name,
sizeof(lsm.session.name));
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_START_TRACE;
lttng_ctl_copy_string(lsm.session.name, session_name,
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_STOP_TRACE;
lttng_ctl_copy_string(lsm.session.name, session_name,
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_TRACEPOINT_FIELDS;
lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_DESTROY_SESSION;
lttng_ctl_copy_string(lsm.session.name, session_name,
int ret;
struct lttcomm_session_msg lsm;
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_SESSIONS;
ret = lttng_ctl_ask_sessiond(&lsm, (void**) sessions);
if (ret < 0) {
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_DOMAINS;
lttng_ctl_copy_string(lsm.session.name, session_name,
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_CHANNELS;
lttng_ctl_copy_string(lsm.session.name, handle->session_name,
sizeof(lsm.session.name));
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_LIST_EVENTS;
lttng_ctl_copy_string(lsm.session.name, handle->session_name,
sizeof(lsm.session.name));
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_CALIBRATE;
lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
return -LTTNG_ERR_INVALID;
}
+ memset(&lsm, 0, sizeof(lsm));
lsm.cmd_type = LTTNG_DATA_PENDING;
lttng_ctl_copy_string(lsm.session.name, session_name,