From ab8f4bf1f4f83385247c0480a7d9b51e0de83ee1 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 3 Oct 2014 21:02:56 +0200 Subject: [PATCH] timeshift: fix some coverity issues --- src/timeshift/timeshift_reader.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index 3a48602d..bb79db99 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -52,8 +52,8 @@ static ssize_t _read_pktbuf ( int fd, pktbuf_t **pktbuf ) if (r != sizeof(sz)) return 0; cnt += r; - /* Empty */ - if (!sz) { + /* Empty And Sanity Check */ + if (!sz || sz > 1024 * 1024) { *pktbuf = NULL; return cnt; } @@ -93,6 +93,9 @@ static ssize_t _read_msg ( int fd, streaming_message_t **sm ) /* EOF */ if (sz == 0) return cnt; + /* Wrong data size */ + if (sz > 1024 * 1024) return -1; + /* Type */ r = read(fd, &type, sizeof(type)); if (r < 0) return -1; @@ -320,10 +323,12 @@ static int _timeshift_read if (*cur_file) { /* Open file */ - if (*fd == -1) { + if (*fd < 0) { tvhtrace("timeshift", "ts %d open file %s", ts->id, (*cur_file)->path); *fd = open((*cur_file)->path, O_RDONLY); + if (*fd < 0) + return -1; } tvhtrace("timeshift", "ts %d seek to %jd", ts->id, (intmax_t)*cur_off); lseek(*fd, *cur_off, SEEK_SET);