Fix: use off_t type for lseek function return value to avoid overflow
authorGregory LEOCADIE <g.leocadie@criteo.com>
Thu, 29 Mar 2018 10:52:30 +0000 (12:52 +0200)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 9 Apr 2018 16:10:25 +0000 (12:10 -0400)
Context: LTTng is configured in live mode with only one channel, getting
traces for a long-running application (days of uptime)

The trace file gets bigger (many GBs), so the offset (bigger than
int.MaxValue). When getting a packet for such offset, the lseek returns
bigger than int.MaxValue. This value is stored in a variable "ret" of
type int. We have an overflow which leads to sending an error to the
viewer (babeltrace), which stops.
[error] get_data_packet: error.
[error] get_data_packet failed
[error] Unknown return code 0

Signed-off-by: Gregory LEOCADIE <g.leocadie@criteo.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/live.c
src/bin/lttng-sessiond/cmd.c
src/common/utils.c

index 96d0a180a27b079834bc0fb16c977e09ad1600a8..70da4a9a71b383c0d8fa70120d7941adeca78582 100644 (file)
@@ -1480,6 +1480,7 @@ static
 int viewer_get_packet(struct relay_connection *conn)
 {
        int ret;
+       off_t lseek_ret;
        char *reply = NULL;
        struct lttng_viewer_get_packet get_packet_info;
        struct lttng_viewer_trace_packet reply_header;
@@ -1521,9 +1522,9 @@ int viewer_get_packet(struct relay_connection *conn)
        }
 
        pthread_mutex_lock(&vstream->stream->lock);
-       ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
+       lseek_ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
                        SEEK_SET);
-       if (ret < 0) {
+       if (lseek_ret < 0) {
                PERROR("lseek fd %d to offset %" PRIu64, vstream->stream_fd->fd,
                        be64toh(get_packet_info.offset));
                goto error;
index 23c6c31a2fc05528476cd5f9d99ba9a1410a72ba..bb46093e2586f4f458d60ad2584f7c97d264c0d3 100644 (file)
@@ -3407,10 +3407,12 @@ static
 int clear_metadata_file(int fd)
 {
        int ret;
+       off_t lseek_ret;
 
-       ret = lseek(fd, 0, SEEK_SET);
-       if (ret < 0) {
+       lseek_ret = lseek(fd, 0, SEEK_SET);
+       if (lseek_ret < 0) {
                PERROR("lseek");
+               ret = -1;
                goto end;
        }
 
index aa11551c30635fd4e423382092fd1871a2534b17..24c3b8ca146ff1fafe8de8da3dd059c7f947f415 100644 (file)
@@ -1335,15 +1335,17 @@ LTTNG_HIDDEN
 int utils_truncate_stream_file(int fd, off_t length)
 {
        int ret;
+       off_t lseek_ret;
 
        ret = ftruncate(fd, length);
        if (ret < 0) {
                PERROR("ftruncate");
                goto end;
        }
-       ret = lseek(fd, length, SEEK_SET);
-       if (ret < 0) {
+       lseek_ret = lseek(fd, length, SEEK_SET);
+       if (lseek_ret < 0) {
                PERROR("lseek");
+               ret = -1;
                goto end;
        }
 end:
This page took 0.036958 seconds and 4 git commands to generate.