]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Fix error checks in sys_utimensat
authorMarc Rittinghaus <marc.rittinghaus@unikraft.io>
Mon, 24 Apr 2023 14:19:25 +0000 (16:19 +0200)
committerUnikraft <monkey@unikraft.io>
Tue, 2 May 2023 20:19:25 +0000 (20:19 +0000)
If successful, asprintf() returns the number of characters written. Due
to the format strings this will always be >0. On error, asprintf()
returns -1, which means the return value will in any case be non-zero,
always leading to a (false) ENOMEM.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Rares Miculescu <miculescur@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #865

lib/vfscore/syscalls.c

index 2b2511c40db4d5dfa30436c86cf767036a5f9892..923f3d409604a3e7cc7ed8828adb4493a3fe3585 100644 (file)
@@ -1422,9 +1422,8 @@ sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], i
                if (!pathname)
                        return EFAULT;
                error = asprintf(&ap, "%s/%s", main_task->t_cwd, pathname);
-               if (error || !ap)
+               if (unlikely(error == -1))
                        return ENOMEM;
-
        } else {
                struct vfscore_file *fp;
 
@@ -1444,7 +1443,7 @@ sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], i
                else
                        error = asprintf(&ap, "%s/%s", fp->f_dentry->d_mount->m_path,
                                        fp->f_dentry->d_path);
-               if (error || !ap)
+               if (unlikely(error == -1))
                        return ENOMEM;
        }