From 961a676e93fe7d599d3856e63bd132fe0d2decb2 Mon Sep 17 00:00:00 2001 From: Jindrich Novy Date: Wed, 27 May 2020 11:16:57 +0200 Subject: Check lseek() for failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Error: CHECKED_RETURN (CWE-252): [#def26] libslirp-4.3.0/src/tftp.c:121: check_return: Calling "lseek(spt->fd, block_nr * spt->block_size, 0)" without checking return value. This library function may fail and return an error code. 119| 120| if (len) { 121|-> lseek(spt->fd, block_nr * spt->block_size, SEEK_SET); 122| 123| bytes_read = read(spt->fd, buf, len); Signed-off-by: Jindrich Novy Reviewed-by: Marc-André Lureau --- src/tftp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tftp.c b/src/tftp.c index c209145..c6950ee 100644 --- a/src/tftp.c +++ b/src/tftp.c @@ -118,7 +118,9 @@ static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr, } if (len) { - lseek(spt->fd, block_nr * spt->block_size, SEEK_SET); + if (lseek(spt->fd, block_nr * spt->block_size, SEEK_SET) == (off_t)-1) { + return -1; + } bytes_read = read(spt->fd, buf, len); } -- cgit v1.1