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

[UNIKRAFT PATCH 5/5] lib/vfscore: Fix possible memleak in getcwd



If path is null and the memory is allocated by us then if size < len
we exit the call without freeing the memory. We solve this by moving the
check for sizer earlier.
---
 lib/vfscore/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index 846e2efd..f8e5e7fb 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -1352,6 +1352,11 @@ char *getcwd(char *path, size_t size)
        size_t len = strlen(t->t_cwd) + 1;
        int error;
 
+       if (size < len) {
+               error = ERANGE;
+               goto out_errno;
+       }
+
        if (!path) {
                if (!size)
                        size = len;
@@ -1367,11 +1372,6 @@ char *getcwd(char *path, size_t size)
                }
        }
 
-       if (size < len) {
-               error = ERANGE;
-               goto out_errno;
-       }
-
        memcpy(path, t->t_cwd, len);
        trace_vfs_getcwd_ret(path);
        return path;
-- 
2.27.0




 


Rackspace

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