Skip to content

Fix | vs. & logic error on check of retval from stat() - #406

Open
klausman wants to merge 2 commits into
markfasheh:masterfrom
klausman:statretcheck
Open

Fix | vs. & logic error on check of retval from stat()#406
klausman wants to merge 2 commits into
markfasheh:masterfrom
klausman:statretcheck

Conversation

@klausman

@klausman klausman commented Jun 2, 2026

Copy link
Copy Markdown

The three checks of stat() return values have a logic bug in that they check if any of the basic stat fields (as bundled by STATX_BASIC_STATS) are there, even though we care about multiple of them (e.g. st.stx_ino, st.stx_size and st.stx_mtime, possibly more).

Fixed the logic check to ensure all basic fields are there (and folded in a smaller bug where | was used when it should have been &).

klausman added 2 commits June 2, 2026 13:28
Comparing this to the other stat() callsites (l.469 and l.734) made me
wonder if `|` is actually the right operation here: we want to make sure
the basic fields are there, but with `|` the inner part will always be
nonzero (and thus `!()` will always be as-zero, defeating the entire
check. I think this is a simple typo and should be `&` instead.
THinking this over some more, I relaized that the lgoic is not quite
correct. As it is (ignoring the earlier `|` vs. `&` bug), we don't check
if the fields we are about are _all_ there (we specifically care about
e.g. st.stx_ino, st.stx_siz and st.stx_size); instead any of the budled
fields in STATX_BASIC_STATS are sufficient to make the check pass.

In reality, only some of the basic fields being there but not all is
extremely unlikely if not impossible. Still, I think the code should
reflect the intended logic, rather than a proximate check as it is now.

So I fixed all three occasions of this check in file_scan.c.
@klausman

klausman commented Jun 2, 2026

Copy link
Copy Markdown
Author

I realized there is another logic bug in these three checks, and fixed the main PR comment accordingly

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.

1 participant