[pseudo][PATCH 08/11] ports/unix: realpath: Fix chroot processing
Mark Hatle <[email protected]>
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <[email protected]> |
From: Mark Hatle <[email protected]> When running realpath from within a chroot, the returned path must be sanitized to appear as if it's within the chroot. Use the existing pseudo_chroot settings to identify and clear the path. AI-Generated: Fix suggested by github copilot (claude opus 4.6) Signed-off-by: Mark Hatle <[email protected]> Signed-off-by: Mark Hatle <[email protected]> --- ports/unix/guts/realpath.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/unix/guts/realpath.c b/ports/unix/guts/realpath.c index 62a92b2..4f91220 100644 --- a/ports/unix/guts/realpath.c +++ b/ports/unix/guts/realpath.c @@ -30,6 +30,21 @@ *(ep--) = '\0'; } + /* If in a chroot, strip the chroot prefix so the caller sees + * a path relative to the chroot root. + */ + if (pseudo_chroot_len && + (size_t)len >= pseudo_chroot_len && + !memcmp(rname, pseudo_chroot, pseudo_chroot_len) && + (rname[pseudo_chroot_len] == '/' || rname[pseudo_chroot_len] == '\0')) { + rname += pseudo_chroot_len; + len -= pseudo_chroot_len; + if (len == 0) { + rname = "/"; + len = 1; + } + } + if (len >= pseudo_sys_path_max()) { errno = ENAMETOOLONG; return NULL; -- 1.8.3.1