Skip to content

utils: use lstat() instead of stat() in ensure_file()#734

Closed
dwahdany wants to merge 1 commit intocontainers:mainfrom
dwahdany:fix/ensure-file-lstat
Closed

utils: use lstat() instead of stat() in ensure_file()#734
dwahdany wants to merge 1 commit intocontainers:mainfrom
dwahdany:fix/ensure-file-lstat

Conversation

@dwahdany
Copy link

@dwahdany dwahdany commented Mar 9, 2026

Fixes #733.

ensure_file() checks !S_ISLNK to reject symlinks as bind-mount destinations, but uses stat() which follows symlinks. Since stat() resolves the symlink before returning, S_ISLNK is never true for valid symlinks, making the check dead code.

Use lstat() so the S_ISLNK check works as intended.

ensure_file() checks !S_ISLNK to reject symlinks as bind-mount
destinations, but uses stat() which follows symlinks. Since stat()
resolves the symlink before returning, S_ISLNK is never true for
valid symlinks, making the check dead code.

Use lstat() so the S_ISLNK check works as intended.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Dariush Wahdany <86673488+dwahdany@users.noreply.github.com>
@dwahdany dwahdany force-pushed the fix/ensure-file-lstat branch from 3abb587 to ef1ec4d Compare March 9, 2026 09:41
@swick
Copy link
Contributor

swick commented Mar 9, 2026

LGTM

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@smcv smcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behaviour change (backwards compat break) which I don't think is necessarily intended. See #733 (comment).

It wouldn't surprise me if bubblewrap users like flatpak are relying on the ability to mount a regular file onto a symlink, and have it mount onto the target (creating the target as a regular file if the symlink is dangling).

I think we need to discuss whether this is in fact a bug, before fixing it.

@smcv
Copy link
Collaborator

smcv commented Mar 20, 2026

From #733, it seems that @dwahdany was misunderstanding the intention of this code. I propose that we clarify the comments instead: #737.

@smcv smcv closed this Mar 20, 2026
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.

ensure_file() uses stat() instead of lstat(), making S_ISLNK check dead code

4 participants