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:
Christopher Haster
2024-11-23 18:25:40 -06:00
parent 815f0d85a5
commit 80ca1ea300
2 changed files with 58 additions and 21 deletions

7
lfs.c
View File

@@ -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;
}