Fix segfault in prt-cache

Co-authored-by: Alexandr Savca <alexandr.savca89@gmail.com>
This commit is contained in:
Tim Biermann 2022-02-27 22:30:23 +01:00
parent da6bfb0a60
commit 8bc31c0745

View File

@ -1806,6 +1806,11 @@ void PrtGet::ls()
if ( p ) { if ( p ) {
string dirname = p->path() + "/" + p->name(); string dirname = p->path() + "/" + p->name();
DIR* dir = opendir(dirname.c_str()); DIR* dir = opendir(dirname.c_str());
if (dir == NULL) {
cerr << "Directory " << dirname << " not found" << endl;
m_returnValue = PG_GENERAL_ERROR;
return;
}
struct dirent* entry; struct dirent* entry;
vector<string> files; vector<string> files;
while ((entry = readdir(dir))) { while ((entry = readdir(dir))) {
@ -1848,7 +1853,7 @@ void PrtGet::cat()
} }
string file = p->path() + "/" + p->name() + "/" + fileName; string file = p->path() + "/" + p->name() + "/" + fileName;
if (!printFile(file)) { if (!printFile(file)) {
cerr << "File '" << *it << "' not found" << endl; cerr << "File '" << fileName << "' not found" << endl;
m_returnValue = PG_GENERAL_ERROR; m_returnValue = PG_GENERAL_ERROR;
return; return;
} }