aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--recovery.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 0b59d12..eed7d04 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -747,6 +747,8 @@ static char* browse_directory(const char* path, Device* device) {
return NULL;
}
+ char pathbuf[PATH_MAX];
+ struct stat st;
int d_size = 0;
int d_alloc = 10;
char** dirs = (char**)malloc(d_alloc * sizeof(char*));
@@ -758,8 +760,12 @@ static char* browse_directory(const char* path, Device* device) {
struct dirent* de;
while ((de = readdir(d)) != NULL) {
int name_len = strlen(de->d_name);
+ snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
- if (de->d_type == DT_DIR) {
+ if (lstat(pathbuf, &st) != 0) {
+ LOGE("Failed to stat %s\n", pathbuf);
+ break;
+ } else if (S_ISDIR(st.st_mode)) {
// skip "." and ".." entries
if (name_len == 1 && de->d_name[0] == '.') continue;
if (name_len == 2 && de->d_name[0] == '.' &&
@@ -774,7 +780,7 @@ static char* browse_directory(const char* path, Device* device) {
dirs[d_size][name_len] = '/';
dirs[d_size][name_len+1] = '\0';
++d_size;
- } else if (de->d_type == DT_REG &&
+ } else if (S_ISREG(st.st_mode) &&
name_len >= 4 &&
strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) {
if (z_size >= z_alloc) {