fix(PIDir): initialize list pointer and check scandir return
dirent** list was uninitialized, so scandir failure (returning -1) left it with indeterminate value. The unconditional free(list) at the end was then UB — typically heap corruption or crash.
This commit is contained in:
@@ -372,7 +372,7 @@ PIVector<PIFile::FileInfo> PIDir::entries(const PIRegularExpression & regexp) {
|
||||
closedir(dir);
|
||||
}
|
||||
# else
|
||||
dirent ** list;
|
||||
dirent ** list = nullptr;
|
||||
int cnt = scandir(p.data(),
|
||||
&list,
|
||||
0,
|
||||
@@ -381,6 +381,7 @@ PIVector<PIFile::FileInfo> PIDir::entries(const PIRegularExpression & regexp) {
|
||||
# else
|
||||
versionsort);
|
||||
# endif
|
||||
if (cnt < 0) return ret;
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
ret << PIFile::fileInfo(dp + PIString(list[i]->d_name));
|
||||
free(list[i]);
|
||||
|
||||
Reference in New Issue
Block a user