sandbox/fs: Use readdir instead of deprecated readdir_r
Using readdir_r limits the maximum file name length and may even be unsafe, and is thus deprecated in since glibc 2.24. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
f189899c2f
commit
bf635ed091
@ -313,7 +313,7 @@ void os_dirent_free(struct os_dirent_node *node)
|
|||||||
|
|
||||||
int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
||||||
{
|
{
|
||||||
struct dirent entry, *result;
|
struct dirent *entry;
|
||||||
struct os_dirent_node *head, *node, *next;
|
struct os_dirent_node *head, *node, *next;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
@ -337,12 +337,15 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (node = head = NULL;; node = next) {
|
for (node = head = NULL;; node = next) {
|
||||||
ret = readdir_r(dir, &entry, &result);
|
errno = 0;
|
||||||
if (ret || !result)
|
entry = readdir(dir);
|
||||||
|
if (!entry) {
|
||||||
|
ret = errno;
|
||||||
break;
|
break;
|
||||||
next = malloc(sizeof(*node) + strlen(entry.d_name) + 1);
|
}
|
||||||
if (dirlen + strlen(entry.d_name) > len) {
|
next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
|
||||||
len = dirlen + strlen(entry.d_name);
|
if (dirlen + strlen(entry->d_name) > len) {
|
||||||
|
len = dirlen + strlen(entry->d_name);
|
||||||
fname = realloc(fname, len);
|
fname = realloc(fname, len);
|
||||||
}
|
}
|
||||||
if (!next || !fname) {
|
if (!next || !fname) {
|
||||||
@ -352,8 +355,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
next->next = NULL;
|
next->next = NULL;
|
||||||
strcpy(next->name, entry.d_name);
|
strcpy(next->name, entry->d_name);
|
||||||
switch (entry.d_type) {
|
switch (entry->d_type) {
|
||||||
case DT_REG:
|
case DT_REG:
|
||||||
next->type = OS_FILET_REG;
|
next->type = OS_FILET_REG;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user