projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: relayd: fail to create session when trace chunk is not found
[lttng-tools.git]
/
src
/
bin
/
lttng-relayd
/
cmd-2-2.c
diff --git
a/src/bin/lttng-relayd/cmd-2-2.c
b/src/bin/lttng-relayd/cmd-2-2.c
index 0450fbf9d7d3c7bde8762fd7e0e4c24a24444372..915b2eb64a41a84acca565cf8b5135bf786d770b 100644
(file)
--- a/
src/bin/lttng-relayd/cmd-2-2.c
+++ b/
src/bin/lttng-relayd/cmd-2-2.c
@@
-1,6
+1,7
@@
/*
* Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
* David Goulet <dgoulet@efficios.com>
/*
* Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
* David Goulet <dgoulet@efficios.com>
+ * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
@@
-16,49
+17,73
@@
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _
GNU
_SOURCE
+#define _
LGPL
_SOURCE
#include <assert.h>
#include <assert.h>
-#include <string.h>
#include <common/common.h>
#include <common/sessiond-comm/relayd.h>
#include <common/common.h>
#include <common/sessiond-comm/relayd.h>
-#include "cmd-generic.h"
+#include <common/compat/endian.h>
+#include <common/compat/string.h>
+#include <lttng/constant.h>
+
#include "cmd-2-1.h"
#include "utils.h"
#include "cmd-2-1.h"
#include "utils.h"
-int cmd_recv_stream_2_2(struct relay_command *cmd, struct relay_stream *stream)
+/*
+ * cmd_recv_stream_2_2 allocates path_name and channel_name.
+ */
+int cmd_recv_stream_2_2(const struct lttng_buffer_view *payload,
+ char **ret_path_name, char **ret_channel_name,
+ uint64_t *tracefile_size, uint64_t *tracefile_count)
{
int ret;
struct lttcomm_relayd_add_stream_2_2 stream_info;
{
int ret;
struct lttcomm_relayd_add_stream_2_2 stream_info;
+ char *path_name = NULL;
+ char *channel_name = NULL;
+ size_t len;
- assert(cmd);
- assert(stream);
-
- ret = cmd_recv(cmd->sock, &stream_info, sizeof(stream_info));
- if (ret < 0) {
- ERR("Unable to recv stream version 2.2");
+ if (payload->size < sizeof(stream_info)) {
+ ERR("Unexpected payload size in \"cmd_recv_stream_2_2\": expected >= %zu bytes, got %zu bytes",
+ sizeof(stream_info), payload->size);
+ ret = -1;
goto error;
}
goto error;
}
+ memcpy(&stream_info, payload->data, sizeof(stream_info));
- stream->path_name = create_output_path(stream_info.pathname);
- if (stream->path_name == NULL) {
+ len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname));
+ /* Ensure that NULL-terminated and fits in local filename length. */
+ if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) {
+ ret = -ENAMETOOLONG;
+ ERR("Path name too long");
+ goto error;
+ }
+ path_name = strdup(stream_info.pathname);
+ if (!path_name) {
PERROR("Path name allocation");
ret = -ENOMEM;
goto error;
}
PERROR("Path name allocation");
ret = -ENOMEM;
goto error;
}
-
- stream->channel_name = strdup(stream_info.channel_name);
- if (stream->channel_name == NULL) {
+ len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name));
+ if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) {
+ ret = -ENAMETOOLONG;
+ ERR("Channel name too long");
+ goto error;
+ }
+ channel_name = strdup(stream_info.channel_name);
+ if (!channel_name) {
ret = -errno;
ret = -errno;
- PERROR("
Path
name allocation");
+ PERROR("
Channel
name allocation");
goto error;
}
goto error;
}
- stream->tracefile_size = be64toh(stream_info.tracefile_size);
- stream->tracefile_count = be64toh(stream_info.tracefile_count);
- ret = 0;
-
+ *tracefile_size = be64toh(stream_info.tracefile_size);
+ *tracefile_count = be64toh(stream_info.tracefile_count);
+ *ret_path_name = path_name;
+ *ret_channel_name = channel_name;
+ return 0;
error:
error:
+ free(path_name);
+ free(channel_name);
return ret;
}
return ret;
}
This page took
0.024746 seconds
and
4
git commands to generate.