diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2023-01-04 16:36:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-04 16:36:43 +0000 |
commit | 9fc7cc262f4bf6ae09af82efe59cbea7f7e330d7 (patch) | |
tree | c86b8c905c79e0bb0c393ecedeac9c084176b949 /lib | |
parent | 3eb7ff6579740a5b962c1a52804b0ec5b29a4c42 (diff) | |
download | libvfio-user-9fc7cc262f4bf6ae09af82efe59cbea7f7e330d7.zip libvfio-user-9fc7cc262f4bf6ae09af82efe59cbea7f7e330d7.tar.gz libvfio-user-9fc7cc262f4bf6ae09af82efe59cbea7f7e330d7.tar.bz2 |
allow -1 file descriptor for ioregionfd (#727)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libvfio-user.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 5a6269a..94524a2 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -483,7 +483,6 @@ vfu_create_ioeventfd(vfu_ctx_t *vfu_ctx, uint32_t region_idx, int fd, vfu_reg_info_t *vfu_reg; assert(vfu_ctx != NULL); - assert(fd >= 0); #ifndef SHADOW_IOEVENTFD if (shadow_fd != -1) { @@ -542,6 +541,15 @@ free_regions(vfu_ctx_t *vfu_ctx) * This function is used to add fd's to the fd return array and gives you back * the index of the fd that has been added. If the fd is already present it will * return the index to that duplicate fd to reduce the number of fd's sent. + * The fd must be a valid fd or -1, any other negative value is not permitted. + * + * out_fds: an array where the fd is stored + * nr_out_fds: pointer to memory that contains the size of the array + * fd_search: the fd to add + * + * returns: the array index where the fd is added to, can be the index of an + * existing fd if this is a duplicate fd. If the fd is -1 then the function + * returns -1. */ static int add_fd_index(int *out_fds, size_t *nr_out_fds, int fd_search) @@ -551,6 +559,11 @@ add_fd_index(int *out_fds, size_t *nr_out_fds, int fd_search) assert(out_fds != NULL); assert(nr_out_fds != NULL); + assert(fd_search >= -1); + if (fd_search == -1) { + return -1; + } + for (i = 0; i < *nr_out_fds; i++) { if (out_fds[i] == fd_search) { return i; |