projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: NULL passed to memcpy in error path
[lttng-tools.git]
/
src
/
bin
/
lttng-relayd
/
live.c
diff --git
a/src/bin/lttng-relayd/live.c
b/src/bin/lttng-relayd/live.c
index 61acafec2098ecd70a5b1889309992e858a0e3cb..8a8550f40f60a9a888cf36c8f62d6509f8d3580b 100644
(file)
--- a/
src/bin/lttng-relayd/live.c
+++ b/
src/bin/lttng-relayd/live.c
@@
-654,12
+654,16
@@
void *thread_dispatcher(void *data)
health_code_update();
health_code_update();
-
while (!CMM_LOAD_SHARED(live_dispatch_thread_exit)
) {
+
for (;;
) {
health_code_update();
/* Atomically prepare the queue futex */
futex_nto1_prepare(&viewer_conn_queue.futex);
health_code_update();
/* Atomically prepare the queue futex */
futex_nto1_prepare(&viewer_conn_queue.futex);
+ if (CMM_LOAD_SHARED(live_dispatch_thread_exit)) {
+ break;
+ }
+
do {
health_code_update();
do {
health_code_update();
@@
-1478,13
+1482,14
@@
error_put:
static
int viewer_get_packet(struct relay_connection *conn)
{
static
int viewer_get_packet(struct relay_connection *conn)
{
- int ret, send_data = 0;
- char *data = NULL;
- uint32_t len = 0;
- ssize_t read_len;
+ int ret;
+ char *reply = NULL;
struct lttng_viewer_get_packet get_packet_info;
struct lttng_viewer_get_packet get_packet_info;
- struct lttng_viewer_trace_packet reply;
+ struct lttng_viewer_trace_packet reply
_header
;
struct relay_viewer_stream *vstream = NULL;
struct relay_viewer_stream *vstream = NULL;
+ uint32_t reply_size = sizeof(reply_header);
+ uint32_t packet_data_len = 0;
+ ssize_t read_len;
DBG2("Relay get data packet");
DBG2("Relay get data packet");
@@
-1498,25
+1503,27
@@
int viewer_get_packet(struct relay_connection *conn)
health_code_update();
/* From this point on, the error label can be reached. */
health_code_update();
/* From this point on, the error label can be reached. */
- memset(&reply
, 0, sizeof(reply
));
+ memset(&reply
_header, 0, sizeof(reply_header
));
vstream = viewer_stream_get_by_id(be64toh(get_packet_info.stream_id));
if (!vstream) {
DBG("Client requested packet of unknown stream id %" PRIu64,
be64toh(get_packet_info.stream_id));
vstream = viewer_stream_get_by_id(be64toh(get_packet_info.stream_id));
if (!vstream) {
DBG("Client requested packet of unknown stream id %" PRIu64,
be64toh(get_packet_info.stream_id));
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
+ reply
_header
.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
goto send_reply_nolock;
goto send_reply_nolock;
+ } else {
+ packet_data_len = be32toh(get_packet_info.len);
+ reply_size += packet_data_len;
}
}
- pthread_mutex_lock(&vstream->stream->lock);
-
- len = be32toh(get_packet_info.len);
- data = zmalloc(len);
- if (!data) {
- PERROR("relay data zmalloc");
+ reply = zmalloc(reply_size);
+ if (!reply) {
+ PERROR("packet reply zmalloc");
+ reply_size = sizeof(reply_header);
goto error;
}
goto error;
}
+ pthread_mutex_lock(&vstream->stream->lock);
ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
SEEK_SET);
if (ret < 0) {
ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
SEEK_SET);
if (ret < 0) {
@@
-1524,50
+1531,50
@@
int viewer_get_packet(struct relay_connection *conn)
be64toh(get_packet_info.offset));
goto error;
}
be64toh(get_packet_info.offset));
goto error;
}
- read_len = lttng_read(vstream->stream_fd->fd, data, len);
- if (read_len < len) {
+ read_len = lttng_read(vstream->stream_fd->fd,
+ reply + sizeof(reply_header),
+ packet_data_len);
+ if (read_len < packet_data_len) {
PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64,
vstream->stream_fd->fd,
be64toh(get_packet_info.offset));
goto error;
}
PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64,
vstream->stream_fd->fd,
be64toh(get_packet_info.offset));
goto error;
}
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_OK);
- reply.len = htobe32(len);
- send_data = 1;
+ reply_header.status = htobe32(LTTNG_VIEWER_GET_PACKET_OK);
+ reply_header.len = htobe32(packet_data_len);
goto send_reply;
error:
goto send_reply;
error:
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
+ reply
_header
.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
send_reply:
if (vstream) {
pthread_mutex_unlock(&vstream->stream->lock);
}
send_reply_nolock:
send_reply:
if (vstream) {
pthread_mutex_unlock(&vstream->stream->lock);
}
send_reply_nolock:
- reply.flags = htobe32(reply.flags);
health_code_update();
health_code_update();
- ret = send_response(conn->sock, &reply, sizeof(reply));
- if (ret < 0) {
- goto end_free;
+ if (reply) {
+ memcpy(reply, &reply_header, sizeof(reply_header));
+ ret = send_response(conn->sock, reply, reply_size);
+ } else {
+ /* No reply to send. */
+ ret = send_response(conn->sock, &reply_header,
+ reply_size);
}
}
- health_code_update();
- if (send_data) {
- health_code_update();
- ret = send_response(conn->sock, data, len);
- if (ret < 0) {
- goto end_free;
- }
- health_code_update();
+ health_code_update();
+ if (ret < 0) {
+ PERROR("sendmsg of packet data failed");
+ goto end_free;
}
}
- DBG("Sent %u bytes for stream %" PRIu64,
len
,
+ DBG("Sent %u bytes for stream %" PRIu64,
reply_size
,
be64toh(get_packet_info.stream_id));
end_free:
be64toh(get_packet_info.stream_id));
end_free:
- free(
data
);
+ free(
reply
);
end:
if (vstream) {
viewer_stream_put(vstream);
end:
if (vstream) {
viewer_stream_put(vstream);
This page took
0.02608 seconds
and
4
git commands to generate.