Add size check to createFileSystem

This commit is contained in:
2017-04-12 21:26:23 -05:00
parent 9f3b338fed
commit 5e80cc80b8
4 changed files with 14 additions and 9 deletions
+2 -2
View File
@@ -16,12 +16,12 @@ namespace clargs {
class ClArgs {
private:
std::map<std::string, bool> m_args;
::std::map<::std::string, bool> m_args;
public:
ClArgs(int argc, const char **args);
bool operator[](std::string arg);
bool operator[](::std::string arg);
};
}
+6 -1
View File
@@ -10,7 +10,7 @@
namespace ox {
namespace fs {
FileSystem *createFileSystem(void *buff) {
FileSystem *createFileSystem(void *buff, size_t buffSize) {
auto version = ((FileStore16*) buff)->version();
auto type = ((FileStore16*) buff)->fsType();
FileSystem *fs = nullptr;
@@ -33,6 +33,11 @@ FileSystem *createFileSystem(void *buff) {
break;
}
if (fs->size() > buffSize) {
delete fs;
fs = nullptr;
}
return fs;
}
+1 -1
View File
@@ -53,7 +53,7 @@ class FileSystem {
virtual uint64_t size() = 0;
};
FileSystem *createFileSystem(void *buff);
FileSystem *createFileSystem(void *buff, size_t buffSize);
template<typename FileStore, FsType FS_TYPE>
class FileSystemTemplate: public FileSystem {
+5 -5
View File
@@ -148,7 +148,7 @@ int read(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) {
auto fs = createFileSystem(fsBuff);
auto fs = createFileSystem(fsBuff, fsSize);
if (fs) {
auto output = fs->read(inode, &fileSize);
@@ -195,7 +195,7 @@ int write(int argc, char **args, bool expand) {
auto srcBuff = loadFileBuff(srcPath, &srcSize);
if (srcBuff) {
auto expanded = false;
auto fs = createFileSystem(fsBuff);
auto fs = createFileSystem(fsBuff, fsSize);
if (fs) {
if (expand && fs->available() <= srcSize) {
auto needed = fs->size() + fs->spaceNeeded(inode, srcSize);
@@ -206,7 +206,7 @@ int write(int argc, char **args, bool expand) {
delete []fsBuff;
fsBuff = cloneBuff;
fs = createFileSystem(fsBuff);
fs = createFileSystem(fsBuff, fsSize);
fsSize = needed;
fs->resize(fsSize);
}
@@ -264,7 +264,7 @@ int compact(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) {
auto fs = createFileSystem(fsBuff);
auto fs = createFileSystem(fsBuff, fsSize);
if (fs) {
fs->resize();
@@ -304,7 +304,7 @@ int remove(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) {
auto fs = createFileSystem(fsBuff);
auto fs = createFileSystem(fsBuff, fsSize);
if (fs) {
err = fs->remove(inode);