Fix: relayd: hostname check is too restrictive
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-2.c
1 /*
2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #define _LGPL_SOURCE
21 #include <assert.h>
22
23 #include <common/common.h>
24 #include <common/sessiond-comm/relayd.h>
25
26 #include <common/compat/endian.h>
27 #include <common/compat/string.h>
28 #include <lttng/constant.h>
29
30 #include "cmd-2-1.h"
31 #include "utils.h"
32
33 /*
34 * cmd_recv_stream_2_2 allocates path_name and channel_name.
35 */
36 int cmd_recv_stream_2_2(const struct lttng_buffer_view *payload,
37 char **ret_path_name, char **ret_channel_name,
38 uint64_t *tracefile_size, uint64_t *tracefile_count)
39 {
40 int ret;
41 struct lttcomm_relayd_add_stream_2_2 stream_info;
42 char *path_name = NULL;
43 char *channel_name = NULL;
44 size_t len;
45
46 if (payload->size < sizeof(stream_info)) {
47 ERR("Unexpected payload size in \"cmd_recv_stream_2_2\": expected >= %zu bytes, got %zu bytes",
48 sizeof(stream_info), payload->size);
49 ret = -1;
50 goto error;
51 }
52 memcpy(&stream_info, payload->data, sizeof(stream_info));
53
54 len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname));
55 /* Ensure that NULL-terminated and fits in local filename length. */
56 if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) {
57 ret = -ENAMETOOLONG;
58 ERR("Path name too long");
59 goto error;
60 }
61 path_name = strdup(stream_info.pathname);
62 if (!path_name) {
63 PERROR("Path name allocation");
64 ret = -ENOMEM;
65 goto error;
66 }
67 len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name));
68 if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) {
69 ret = -ENAMETOOLONG;
70 ERR("Channel name too long");
71 goto error;
72 }
73 channel_name = strdup(stream_info.channel_name);
74 if (!channel_name) {
75 ret = -errno;
76 PERROR("Channel name allocation");
77 goto error;
78 }
79
80 *tracefile_size = be64toh(stream_info.tracefile_size);
81 *tracefile_count = be64toh(stream_info.tracefile_count);
82 *ret_path_name = path_name;
83 *ret_channel_name = channel_name;
84 return 0;
85 error:
86 free(path_name);
87 free(channel_name);
88 return ret;
89 }
This page took 0.030183 seconds and 4 git commands to generate.