diff mbox series

[pseudo] ports/linux/guts: Fix uninitialized pseudo_path in open_tree wrappers

Message ID 20261021122614.751395-1-frezidok1@gmail.com
State New
Headers show
Series [pseudo] ports/linux/guts: Fix uninitialized pseudo_path in open_tree wrappers | expand

Commit Message

Dmitry Sakhonchik Oct. 21, 2026, 12:26 p.m. UTC
From: Dmitry Sakhonchik <frezidok1@gmail.com>

Signed-off-by: Dmitry Sakhonchik <frezidok1@gmail.com>
---
 ports/linux/guts/open_tree.c      | 11 +++++++++--
 ports/linux/guts/open_tree_attr.c | 11 +++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ports/linux/guts/open_tree.c b/ports/linux/guts/open_tree.c
index ca299a1..658b165 100644
--- a/ports/linux/guts/open_tree.c
+++ b/ports/linux/guts/open_tree.c
@@ -16,6 +16,15 @@ 
 		pseudo_diag("ERROR: OPEN_TREE_CLONE is not supported\n");
 	}
 
+	/* This wrapper is not called with modified paths, therefore we have to handle this ourselves.
+	   We can't use the standard mappings since the function needs relative paths to be preserved,
+	   they can't be our usual absolute paths. An example difference:
+	   open_tree(dirfd, "/dir1/dir2", 0) = -1 ENOENT (No such file or directory)
+	   vs.
+	   open_tree(dirfd, "dir1/dir2", 0) = 4
+	   FIXME - we don't handle chroot for relative paths
+	*/
+	pseudo_path = pseudo_root_path(__func__, __LINE__, dirfd, path, 0);
 	if (path && path[0] == '/') {
 		/* If the path is absolute, we should account for a potential chroot */
 		path = pseudo_path;
@@ -37,8 +46,6 @@ 
 		save_errno = errno;
 		int stat_rc;
 
-		pseudo_path = pseudo_root_path(__func__, __LINE__, dirfd, path, 0);
-
 		stat_rc = real___fxstatat64(_STAT_VER, dirfd, pseudo_path, &buf, (flags & AT_SYMLINK_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
 
 		pseudo_debug(PDBGF_FILE, "open_tree(path %s), flags %o, stat rc %d, stat mode %o\n",
diff --git a/ports/linux/guts/open_tree_attr.c b/ports/linux/guts/open_tree_attr.c
index 3cf8fc7..c2b1b0d 100644
--- a/ports/linux/guts/open_tree_attr.c
+++ b/ports/linux/guts/open_tree_attr.c
@@ -18,6 +18,15 @@ 
 		pseudo_diag("ERROR: OPEN_TREE_CLONE is not supported\n");
 	}
 
+	/* This wrapper is not called with modified paths, therefore we have to handle this ourselves.
+	   We can't use the standard mappings since the function needs relative paths to be preserved,
+	   they can't be our usual absolute paths. An example difference:
+	   open_tree_attr(dirfd, "/dir1/dir2", 0, NULL, 0) = -1 ENOENT (No such file or directory)
+	   vs.
+	   open_tree_attr(dirfd, "dir1/dir2", 0, NULL, 0) = 4
+	   FIXME - we don't handle chroot for relative paths
+	*/
+	pseudo_path = pseudo_root_path(__func__, __LINE__, dirfd, path, 0);
 	if (path && path[0] == '/') {
 		/* If the path is absolute, we should account for a potential chroot */
 		path = pseudo_path;
@@ -35,8 +44,6 @@ 
 		save_errno = errno;
 		int stat_rc;
 
-		pseudo_path = pseudo_root_path(__func__, __LINE__, dirfd, path, 0);
-
 		stat_rc = real___fxstatat64(_STAT_VER, dirfd, pseudo_path, &buf, (flags & AT_SYMLINK_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
 
 		pseudo_debug(PDBGF_FILE, "open_tree_attr(path %s), flags %o, stat rc %d, stat mode %o\n",