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

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


  • To: minios-devel <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU <vlad_andrei.badoiu@xxxxxx>
  • Date: Sat, 21 Nov 2020 17:58:17 +0200 (EET)
  • Cc: felipe huici <felipe.huici@xxxxxxxxx>, Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
  • Delivery-date: Sat, 21 Nov 2020 15:58:22 +0000
  • Dkim-filter: OpenDKIM Filter v2.10.3 mx.upb.ro B0C58B561C89
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: Uon0q9YDvW+DeJO91BFTxcHKNHQNyg==
  • Thread-topic: lib/vfscore: Fix possible memleak in getcwd

Hi,

I forgot to add the:

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxx>

Let me know if I should resend them. Thanks!
----- Original Message -----
From: "Vlad-Andrei Badoiu" <vlad_andrei.badoiu@xxxxxx>
To: "minios-devel" <minios-devel@xxxxxxxxxxxxx>
Cc: "felipe huici" <felipe.huici@xxxxxxxxx>, "Simon Kuenzer" 
<simon.kuenzer@xxxxxxxxx>, "Vlad-Andrei Badoiu" <vlad_andrei.badoiu@xxxxxx>
Sent: Saturday, November 21, 2020 5:07:31 PM
Subject: [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®.