From c6d8daecd38d23b32c3a11ae471f0134594488b0 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Fri, 23 Sep 2022 08:50:43 +0200 Subject: [PATCH] log: fix coverity warning CID 1515529 Checks ftell return value for negative/error --- src/log-pcap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/log-pcap.c b/src/log-pcap.c index d78539c7ac..ebf4335782 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -516,9 +516,13 @@ static inline int PcapWrite( #ifdef HAVE_LIBLZ4 else if (pl->compression.format == PCAP_LOG_COMPRESSION_FORMAT_LZ4) { pcap_dump_flush(pl->pcap_dumper); - uint64_t in_size = (uint64_t)ftell(comp->pcap_buf_wrapper); - uint64_t out_size = LZ4F_compressUpdate( - comp->lz4f_context, comp->buffer, comp->buffer_size, comp->pcap_buf, in_size, NULL); + long in_size = ftell(comp->pcap_buf_wrapper); + if (in_size < 0) { + SCLogError(SC_ERR_PCAP_LOG_COMPRESS, "ftell failed with: %s", strerror(errno)); + return TM_ECODE_FAILED; + } + uint64_t out_size = LZ4F_compressUpdate(comp->lz4f_context, comp->buffer, comp->buffer_size, + comp->pcap_buf, (uint64_t)in_size, NULL); if (LZ4F_isError(len)) { SCLogError(SC_ERR_PCAP_LOG_COMPRESS, "LZ4F_compressUpdate: %s", LZ4F_getErrorName(len)); return TM_ECODE_FAILED;