Skip to content

Fix trailing-slash mkdir under sysroot#102

Merged
jserv merged 1 commit into
mainfrom
mkdir
Jun 17, 2026
Merged

Fix trailing-slash mkdir under sysroot#102
jserv merged 1 commit into
mainfrom
mkdir

Conversation

@jserv

@jserv jserv commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

proc_resolve_sysroot_create_path located the leaf separator with strrchr on the resolved sysroot path. A guest path ending in a slash made strrchr match that trailing slash, so the parent buffer collapsed to the target itself. The parent-existence access() then failed and the resolver wrongly fell back to the host literal path (or auto-created the target as if it were its own parent), so mkdir("/dir/") reported ENOENT or EEXIST instead of creating the directory in the sysroot.

Drop trailing slashes before splitting off the leaf so the check sees the real parent. Guard all-slash guest paths ("/", "///") up front: they name the root, which always exists and has no parent, and trimming would otherwise walk strrchr into the sysroot prefix and trip the containment check (ELOOP) on a multi-component sysroot.

Close #100


Summary by cubic

Fixes trailing-slash handling in sysroot path resolution so mkdir("/dir/") creates the directory under the sysroot instead of returning ENOENT/EEXIST or falling back to the host. Also correctly treats "/", "///" as the root.

  • Bug Fixes
    • Trim trailing slashes before splitting the leaf in proc_resolve_sysroot_create_path so the parent check uses the real parent.
    • Handle all-slash guest paths as root and add tests for root mkdir and trailing-slash mkdir under "/tmp" to verify correct routing inside the sysroot.

Written for commit fb7bb95. Summary will update on new commits.

Review in cubic

proc_resolve_sysroot_create_path located the leaf separator with
strrchr on the resolved sysroot path. A guest path ending in a slash
made strrchr match that trailing slash, so the parent buffer collapsed
to the target itself. The parent-existence access() then failed and the
resolver wrongly fell back to the host literal path (or auto-created the
target as if it were its own parent), so mkdir("/dir/") reported ENOENT
or EEXIST instead of creating the directory in the sysroot.

Drop trailing slashes before splitting off the leaf so the check sees
the real parent. Guard all-slash guest paths ("/", "///") up front:
they name the root, which always exists and has no parent, and trimming
would otherwise walk strrchr into the sysroot prefix and trip the
containment check (ELOOP) on a multi-component sysroot.

Close #100
@jserv

jserv commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@doanbaotrung , Please validate this PR.

cubic-dev-ai[bot]

This comment was marked as resolved.

@doanbaotrung

Copy link
Copy Markdown

It worked!

@jserv jserv merged commit 66635fd into main Jun 17, 2026
5 checks passed
@jserv jserv deleted the mkdir branch June 17, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: mkdir/mkdirat fails with ENOENT when directory path has a trailing slash

2 participants