[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT VFS PATCH v2 2/4] Check for NULL reference on vfscore_put_fd()



Since we can allocate a fd without assigning a
vfscore_file we must protect against NULL pointers.

An example is the LWIP sock_fd_alloc function from sockets.c
which firstly reserves a file descriptor by calling vfscore_alloc_fd
and, on failure, calls vfscore_put_fd. But the failure might occur
before associating an actual vfscore_file with the fd.

Signed-off-by: Mihai Pogonaru <pogonarumihai@xxxxxxxxx>
---
 lib/vfscore/fd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c
index f8b24020..01025a46 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/fd.c
@@ -88,7 +88,12 @@ void vfscore_put_fd(int fd)
        fdtable.files[fd] = NULL;
        ukplat_lcpu_restore_irqf(flags);
 
-       fdrop(fp);
+       /*
+        * Since we can alloc a fd without assigning a
+        * vfsfile we must protect against NULL ptr
+        */
+       if (fp)
+               fdrop(fp);
 }
 
 int vfscore_install_fd(int fd, struct vfscore_file *file)
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.