mirror of https://github.com/ARMmbed/mbed-os.git
Fix NULL pointer indirection in FilePath
If the FileBase::lookup operation in the constructor of FilePath returns NULL, subsequent operations (such as isFile()/isFileSystem()) will call methods on a NULL 'fb' pointer. This commit fixes this issue by adding explicit NULL checks and a new method in FilePath (exists()).pull/54/merge
parent
96101aed32
commit
ae16d3efa8
|
|
@ -34,6 +34,7 @@ public:
|
|||
|
||||
bool isFile(void);
|
||||
FileLike* file(void);
|
||||
bool exists(void);
|
||||
|
||||
private:
|
||||
const char* file_name;
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
|
|||
file_name++;
|
||||
}
|
||||
|
||||
FileBase::lookup(file_system, len);
|
||||
|
||||
|
||||
fb = FileBase::lookup(file_system, len);
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +44,8 @@ const char* FilePath::fileName(void) {
|
|||
}
|
||||
|
||||
bool FilePath::isFileSystem(void) {
|
||||
if (NULL == fb)
|
||||
return false;
|
||||
return (fb->getPathType() == FileSystemPathType);
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +57,8 @@ FileSystemLike* FilePath::fileSystem(void) {
|
|||
}
|
||||
|
||||
bool FilePath::isFile(void) {
|
||||
if (NULL == fb)
|
||||
return false;
|
||||
return (fb->getPathType() == FilePathType);
|
||||
}
|
||||
|
||||
|
|
@ -68,4 +69,8 @@ FileLike* FilePath::file(void) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool FilePath::exists(void) {
|
||||
return fb != NULL;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
|||
|
|
@ -163,7 +163,9 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
|
|||
} else {
|
||||
FilePath path(name);
|
||||
|
||||
if (path.isFile()) {
|
||||
if (!path.exists())
|
||||
return -1;
|
||||
else if (path.isFile()) {
|
||||
res = path.file();
|
||||
} else {
|
||||
FileSystemLike *fs = path.fileSystem();
|
||||
|
|
|
|||
Loading…
Reference in New Issue