diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2020-11-23 07:02:43 -0500 |
---|---|---|
committer | Thanos <tmakatos@gmail.com> | 2020-11-23 12:56:08 +0000 |
commit | 29a4b2bd14879c658717a3ac52120a2997979636 (patch) | |
tree | 4a64603370e5a8e343f3b1737a1f50d3c3c083dd /lib/dma.c | |
parent | a4e19fb88d7bc7fe63cf6ee576ad768368a839a5 (diff) | |
download | libvfio-user-29a4b2bd14879c658717a3ac52120a2997979636.zip libvfio-user-29a4b2bd14879c658717a3ac52120a2997979636.tar.gz libvfio-user-29a4b2bd14879c658717a3ac52120a2997979636.tar.bz2 |
don't pass -1 to fstat
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/dma.c')
-rw-r--r-- | lib/dma.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -61,6 +61,11 @@ fds_are_same_file(int fd1, int fd2) { struct stat st1, st2; + if (fd1 == -1 || fd2 == -1) { + errno = EINVAL; + return -1; + } + return (fstat(fd1, &st1) == 0 && fstat(fd2, &st2) == 0 && st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); } @@ -206,6 +211,11 @@ dma_controller_add_region(dma_controller_t *dma, dma_memory_region_t *region; int page_size; + if (fd == -1) { + errno = EINVAL; + return -1; + } + for (idx = 0; idx < dma->nregions; idx++) { region = &dma->regions[idx]; |