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

[Minios-devel] [UNIKRAFT VFS PATCH 2/3] Check for NULL reference on vfscore_put_fd(). Add asserts to fdrop()



Signed-off-by: Mihai Pogonaru <pogonarumihai@xxxxxxxxx>
---
 lib/vfscore/fd.c   | 7 ++++++-
 lib/vfscore/file.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

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)
diff --git a/lib/vfscore/file.c b/lib/vfscore/file.c
index e7627e96..bc8b0dc8 100644
--- a/lib/vfscore/file.c
+++ b/lib/vfscore/file.c
@@ -42,7 +42,12 @@
 
 int fdrop(struct vfscore_file *fp)
 {
-       int prev = ukarch_dec(&fp->f_count);
+       int prev;
+
+       UK_ASSERT(fp);
+       UK_ASSERT(fp->f_count > 0);
+
+       prev = ukarch_dec(&fp->f_count);
 
        if (prev == 0)
                UK_CRASH("Unbalanced fhold/fdrop");
-- 
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®.