Skip to content

Commit

Permalink
[sb2] Don't bail early if we can map the NULL path. JB#55042
Browse files Browse the repository at this point in the history
  • Loading branch information
krnlyng committed Jan 12, 2023
1 parent 6b8dd35 commit 47f6c7a
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions pathmapping/pathmapping_interf.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,11 @@ void sbox_map_path_at(
{
const char *dirfd_path;

if (!virtual_path) {
res->mres_result_buf = res->mres_result_path = NULL;
res->mres_readonly = 1;
return;
}
if (*virtual_path == '\0') {
goto end;
}

if ((*virtual_path == '/')
if (virtual_path && ((*virtual_path == '/')
#ifdef AT_FDCWD
|| (dirfd == AT_FDCWD)
#endif
) {
)) {
/* same as sbox_map_path() */
fwd_map_path(
(sbox_binary_name ? sbox_binary_name : "UNKNOWN"),
Expand All @@ -273,10 +264,17 @@ void sbox_map_path_at(
/* pathname found */
char *virtual_abs_path_at_fd = NULL;

if (asprintf(&virtual_abs_path_at_fd, "%s/%s", dirfd_path, virtual_path) < 0) {
/* asprintf failed */
abort();
}
if (!virtual_path) {
if (asprintf(&virtual_abs_path_at_fd, "%s", dirfd_path) < 0) {
/* asprintf failed */
abort();
}
} else {
if (asprintf(&virtual_abs_path_at_fd, "%s/%s", dirfd_path, virtual_path) < 0) {
/* asprintf failed */
abort();
}
}
SB_LOG(SB_LOGLEVEL_DEBUG,
"Synthetic path for %s(%d,'%s') => '%s'",
func_name, dirfd, virtual_path, virtual_abs_path_at_fd);
Expand All @@ -289,15 +287,6 @@ void sbox_map_path_at(

return;
}

end:
/* name not found. Can't do much here, log a warning and return
* the original relative path. That will work if we are lucky, but
* not always.. */
SB_LOG(SB_LOGLEVEL_WARNING, "Path not found for FD %d, for %s(%s)",
dirfd, func_name, virtual_path);
res->mres_result_buf = res->mres_result_path = strdup(virtual_path);
res->mres_readonly = 0;
}

/* this maps the path and then leaves "rule" and "exec_policy" to the stack,
Expand Down

0 comments on commit 47f6c7a

Please sign in to comment.