aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-07-25 07:22:47 -0400
committerDamjan Marion <dmarion@me.com>2019-07-25 15:12:28 +0000
commit6c84fb2ee1bf230951aaf92d9db595d4c0feac45 (patch)
treef83b1c69ffbaf9f8c9526d417a93a89435cab005 /src
parentd39495d0bb93675cb80c0514192b2f1412de3db6 (diff)
vppinfra: fix coverity warning in mpcap.c
Type: fix Ticket: VPP-1649 Change-Id: Ief77ec8d5f06bfcc63af6454c4cd9979cf0ab49d Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/mpcap.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/vppinfra/mpcap.c b/src/vppinfra/mpcap.c
index 902f52f1870..3ad67a9ac56 100644
--- a/src/vppinfra/mpcap.c
+++ b/src/vppinfra/mpcap.c
@@ -92,7 +92,7 @@ mpcap_init (mpcap_main_t * pm)
return 0;
if (!pm->file_name)
- pm->file_name = "/tmp/vnet.mpcap";
+ pm->file_name = "/tmp/vppinfra.mpcap";
if (pm->flags & MPCAP_FLAG_THREAD_SAFE)
clib_spinlock_init (&pm->lock);
@@ -172,16 +172,23 @@ mpcap_map (mpcap_main_t * pm)
u32 min_packet_bytes = ~0;
u32 max_packet_bytes = 0;
- if (stat (pm->file_name, &statb) < 0)
+ fd = open (pm->file_name, O_RDONLY);
+ if (fd < 0)
+ {
+ error = clib_error_return_unix (0, "open `%s'", pm->file_name);
+ goto done;
+ }
+
+ if (fstat (fd, &statb) < 0)
{
error = clib_error_return_unix (0, "stat `%s'", pm->file_name);
goto done;
}
- fd = open (pm->file_name, O_RDONLY);
- if (fd < 0)
+ if ((statb.st_mode & S_IFREG) == 0)
{
- error = clib_error_return_unix (0, "open `%s'", pm->file_name);
+ error = clib_error_return (0, "'%s' is not a regular file",
+ pm->file_name);
goto done;
}
@@ -206,6 +213,8 @@ mpcap_map (mpcap_main_t * pm)
if (fh->magic != 0xa1b2c3d4)
{
error = clib_error_return (0, "bad magic `%s'", pm->file_name);
+ pm->flags &= ~(MPCAP_FLAG_INIT_DONE);
+ (void) munmap (pm->file_baseva, pm->max_file_size);
goto done;
}