[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [UNIKRAFT PATCH 5/5] 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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |