1
0
Fork 0
forked from nuttx/nuttx-update

fs/romfs: fix bug about compare path with same prefix

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-03-28 23:10:11 +08:00 committed by Petro Karashchenko
parent 3ed4496a76
commit ca8ce37433

View file

@ -50,6 +50,16 @@
#define LINK_FOLLOWED 1
#define NODEINFO_NINCR 4
/****************************************************************************
* Private Types
****************************************************************************/
struct romfs_entryname_s
{
FAR const char *re_name;
size_t re_len;
};
/****************************************************************************
* Private Functions
****************************************************************************/
@ -268,17 +278,22 @@ static int romfs_followhardlinks(FAR struct romfs_mountpt_s *rm,
static int romfs_nodeinfo_search(FAR const void *a, FAR const void *b)
{
FAR struct romfs_nodeinfo_s *nodeinfo = *(FAR struct romfs_nodeinfo_s **)b;
FAR const struct romfs_entryname_s *entry = a;
FAR const char *name2 = nodeinfo->rn_name;
FAR const char *name1 = a;
size_t len = nodeinfo->rn_namesize;
int ret;
ret = strncmp(name1, name2, len);
if (len > entry->re_len)
{
len = entry->re_len;
}
ret = strncmp(entry->re_name, name2, len);
if (!ret)
{
if (name1[len] == '/' || name1[len] == '\0')
if (entry->re_name[len] == '/' || entry->re_name[len] == '\0')
{
return 0;
return name2[len] == '\0' ? 0 : -1;
}
else
{
@ -291,9 +306,12 @@ static int romfs_nodeinfo_search(FAR const void *a, FAR const void *b)
static int romfs_nodeinfo_compare(FAR const void *a, FAR const void *b)
{
FAR const char *name = (*(FAR struct romfs_nodeinfo_s **)a)->rn_name;
FAR struct romfs_nodeinfo_s *nodeinfo = *(FAR struct romfs_nodeinfo_s **)a;
struct romfs_entryname_s entry;
return romfs_nodeinfo_search(name, b);
entry.re_name = nodeinfo->rn_name;
entry.re_len = nodeinfo->rn_namesize;
return romfs_nodeinfo_search(&entry, b);
}
#endif
@ -312,8 +330,11 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm,
{
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
FAR struct romfs_nodeinfo_s **cnodeinfo;
struct romfs_entryname_s entry;
cnodeinfo = bsearch(entryname, nodeinfo->rn_child, nodeinfo->rn_count,
entry.re_name = entryname;
entry.re_len = entrylen;
cnodeinfo = bsearch(&entry, nodeinfo->rn_child, nodeinfo->rn_count,
sizeof(*nodeinfo->rn_child), romfs_nodeinfo_search);
if (cnodeinfo)
{