- Notifications
You must be signed in to change notification settings - Fork937
Add null pointer check for lfs_dir_fetchmatch#1159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
geky-bot commentedOct 21, 2025
Tests passed ✓, Code: 17132 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
|
BenBE commentedOct 21, 2025
Rationale as explained in#1158 (comment) … |
geky commentedOct 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi@liconghui628, thanks for creating an issue + PR.
Hmmm. It's true Earlier in this loop we check if the tag is "valid" (if the sign bit is clear), and Lines 1182 to 1186 inadad0fb
Lines 351 to 353 inadad0fb
Nothing else touches Short of in-RAM corruption or some other bug. |
liconghui628 commentedOct 23, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@geky This question is indeed very strange. I tried to add some printing information, and in fact, it did call up here. |
geky commentedOct 23, 2025
Ah!@liconghui628, this looks like an older version of the codebase. In particular it's missing this patch:#337, which was merged inv2.1.4. I believe this is the same issue. |
BenBE commentedOct 23, 2025
Would it make sense to include the NULL pointer check anyway; and be it as an assertion at the call site of |
geky commentedOct 23, 2025
I'm not opposed to it, but what would it really add over hardfaulting? Both point out this There's a lot of things that can be NULL in C, fortunately even microcontrollers these days make NULL dereferences "safe" and easy to find. The log@liconghui628 shared even had a full backtrace + |
liconghui628 commentedOct 24, 2025
@geky@BenBE Thank you for your patient explanation. From the perspective of internal implementation alone, I think NULL detection is necessary because it is uncertain whether external modifications will be executed here in the future, the impact on business is quite significant. We just need to make the interface implementation more robust, without worrying about how it is called externally. |
bmcdonnell-fb commentedOct 24, 2025
IMO, it's valuable to make intent/expectations explicit between |
geky commentedNov 10, 2025
I'm still not convinced an assert adds value over just dereferencing the callback, but we can add an @liconghui628, if you change this to This is currently tested in CI and won't change without a new major version. |
Uh oh!
There was an error while loading.Please reload this page.
The internal interface of littlfs calls lfs_dir_fetchmatch with a null cb parameter, and lfs_dir_fetchmatch does not internally determine cb, which may directly call and cause the program to crash.
static int lfs_dir_fetch(lfs_t *lfs,
lfs_mdir_t *dir, const lfs_block_t pair[2]) {
// note, mask=-1, tag=-1 can never match a tag since this
// pattern has the invalid bit set
return (int)lfs_dir_fetchmatch(lfs, dir, pair,
(lfs_tag_t)-1, (lfs_tag_t)-1, NULL, NULL, NULL);
}