Skip to content

Commit 953a8c4

Browse files
committed
utils: crun_safe_ensure_at opens empty paths
if `do_open` is used with an empty path, the reopen the `dirpath`. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 372446d commit 953a8c4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libcrun/utils.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ crun_safe_ensure_at (bool do_open, bool dir, int dirfd, const char *dirpath,
449449

450450
/* Empty path, nothing to do. */
451451
if (*path == '\0')
452-
return 0;
452+
{
453+
if (do_open)
454+
return open (dirpath, O_CLOEXEC | O_PATH, 0);
455+
return 0;
456+
}
453457

454458
npath = xstrdup (path);
455459

@@ -577,12 +581,12 @@ crun_safe_ensure_at (bool do_open, bool dir, int dirfd, const char *dirpath,
577581
int
578582
crun_safe_create_and_open_ref_at (bool dir, int dirfd, const char *dirpath, const char *path, int mode, libcrun_error_t *err)
579583
{
580-
int fd;
584+
int ret;
581585

582586
/* If the file/dir already exists, just open it. */
583-
fd = safe_openat (dirfd, dirpath, path, O_PATH | O_CLOEXEC, 0, err);
584-
if (LIKELY (fd >= 0))
585-
return fd;
587+
ret = safe_openat (dirfd, dirpath, path, O_PATH | O_CLOEXEC, 0, err);
588+
if (LIKELY (ret >= 0))
589+
return ret;
586590

587591
crun_error_release (err);
588592
return crun_safe_ensure_at (true, dir, dirfd, dirpath, path, mode, MAX_READLINKS, err);

0 commit comments

Comments
 (0)