forked from Imagelibrary/littlefs
paths: Reject empty paths
Before this, the empty path ("") was treated as an alias for the root.
This was unintentional and just a side-effect of how the path parser
worked.
Now, the empty path should always result in LFS_ERR_INVAL:
- before: lfs_stat("") => 0
- after: lfs_stat("") => LFS_ERR_INVAL
This commit is contained in:
7
lfs.c
7
lfs.c
@@ -1492,6 +1492,11 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
|
||||
dir->tail[0] = lfs->root[0];
|
||||
dir->tail[1] = lfs->root[1];
|
||||
|
||||
// empty paths are not allowed
|
||||
if (*name == '\0') {
|
||||
return LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
nextname:
|
||||
// skip slashes if we're a directory
|
||||
@@ -1538,7 +1543,7 @@ nextname:
|
||||
}
|
||||
|
||||
// found path
|
||||
if (name[0] == '\0') {
|
||||
if (*name == '\0') {
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user