Skip to content

Commit

Permalink
[sb2] Don't bail early if we can map the NULL path. JB#59837
Browse files Browse the repository at this point in the history
  • Loading branch information
krnlyng committed Aug 22, 2023
1 parent 5c26229 commit dcd7466
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)
|| (dirfd == AT_FDCWD)
#endif
) {
)) {
/* same as sbox_map_path() */
fwd_map_path(
(sbox_binary_name ? sbox_binary_name : "UNKNOWN"),
Expand All @@ -273,9 +264,16 @@ 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 || *virtual_path == '\0') {
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'",
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 dcd7466

Please sign in to comment.