mirror of
https://github.com/akuker/RASCSI.git
synced 2025-08-15 08:27:34 +00:00
Check image file nesting level
This commit is contained in:
@@ -1250,6 +1250,7 @@ bool ParseArgument(int argc, char* argv[], int& port)
|
|||||||
cerr << "Invalid image file scan depth " << optarg << endl;
|
cerr << "Invalid image file scan depth " << optarg << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
rascsi_image.SetDepth(scan_depth);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
|
@@ -44,6 +44,13 @@ RascsiImage::RascsiImage()
|
|||||||
else {
|
else {
|
||||||
default_image_folder = "/home/pi/images";
|
default_image_folder = "/home/pi/images";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RascsiImage::CheckDepth(const string& folder)
|
||||||
|
{
|
||||||
|
return count(folder.begin(), folder.end(), '/') <= depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RascsiImage::CreateImageFolder(int fd, const string& filename)
|
bool RascsiImage::CreateImageFolder(int fd, const string& filename)
|
||||||
@@ -122,6 +129,10 @@ bool RascsiImage::CreateImage(int fd, const PbCommand& command)
|
|||||||
return ReturnStatus(fd, false, "Can't create image file: Missing image filename");
|
return ReturnStatus(fd, false, "Can't create image file: Missing image filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(filename)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + filename + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
string full_filename = default_image_folder + "/" + filename;
|
string full_filename = default_image_folder + "/" + filename;
|
||||||
if (!IsValidDstFilename(full_filename)) {
|
if (!IsValidDstFilename(full_filename)) {
|
||||||
return ReturnStatus(fd, false, "Can't create image file: '" + full_filename + "': File already exists");
|
return ReturnStatus(fd, false, "Can't create image file: '" + full_filename + "': File already exists");
|
||||||
@@ -186,6 +197,10 @@ bool RascsiImage::DeleteImage(int fd, const PbCommand& command)
|
|||||||
return ReturnStatus(fd, false, "Missing image filename");
|
return ReturnStatus(fd, false, "Missing image filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(filename)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + filename + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
string full_filename = default_image_folder + "/" + filename;
|
string full_filename = default_image_folder + "/" + filename;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
@@ -242,6 +257,14 @@ bool RascsiImage::RenameImage(int fd, const PbCommand& command)
|
|||||||
return ReturnStatus(fd, false, "Can't rename image file '" + from + "': Missing destination filename");
|
return ReturnStatus(fd, false, "Can't rename image file '" + from + "': Missing destination filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(from)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + from + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(to)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + to + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
to = default_image_folder + "/" + to;
|
to = default_image_folder + "/" + to;
|
||||||
if (!IsValidDstFilename(to)) {
|
if (!IsValidDstFilename(to)) {
|
||||||
return ReturnStatus(fd, false, "Can't rename image file '" + from + "' to '" + to + "': File already exists");
|
return ReturnStatus(fd, false, "Can't rename image file '" + from + "' to '" + to + "': File already exists");
|
||||||
@@ -277,6 +300,14 @@ bool RascsiImage::CopyImage(int fd, const PbCommand& command)
|
|||||||
return ReturnStatus(fd, false, "Can't copy image file '" + from + "': Missing destination filename");
|
return ReturnStatus(fd, false, "Can't copy image file '" + from + "': Missing destination filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(from)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + from + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CheckDepth(to)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + to + "'").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
to = default_image_folder + "/" + to;
|
to = default_image_folder + "/" + to;
|
||||||
if (!IsValidDstFilename(to)) {
|
if (!IsValidDstFilename(to)) {
|
||||||
return ReturnStatus(fd, false, "Can't copy image file '" + from + "' to '" + to + "': File already exists");
|
return ReturnStatus(fd, false, "Can't copy image file '" + from + "' to '" + to + "': File already exists");
|
||||||
@@ -342,9 +373,11 @@ bool RascsiImage::SetImagePermissions(int fd, const PbCommand& command)
|
|||||||
if (filename.empty()) {
|
if (filename.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing image filename");
|
return ReturnStatus(fd, false, "Missing image filename");
|
||||||
}
|
}
|
||||||
if (filename.find('/') != string::npos) {
|
|
||||||
return ReturnStatus(fd, false, "The image filename '" + filename + "' must not contain a path");
|
if (!CheckDepth(filename)) {
|
||||||
|
return ReturnStatus(fd, false, ("Invalid folder hierarchy depth '" + filename + "'").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = default_image_folder + "/" + filename;
|
filename = default_image_folder + "/" + filename;
|
||||||
if (!IsValidSrcFilename(filename)) {
|
if (!IsValidSrcFilename(filename)) {
|
||||||
return ReturnStatus(fd, false, "Can't modify image file '" + filename + "': Invalid name or type");
|
return ReturnStatus(fd, false, "Can't modify image file '" + filename + "': Invalid name or type");
|
||||||
|
@@ -22,6 +22,8 @@ public:
|
|||||||
RascsiImage();
|
RascsiImage();
|
||||||
~RascsiImage() {};
|
~RascsiImage() {};
|
||||||
|
|
||||||
|
void SetDepth(int depth) { this->depth = depth; }
|
||||||
|
bool CheckDepth(const string&);
|
||||||
bool CreateImageFolder(int, const string&);
|
bool CreateImageFolder(int, const string&);
|
||||||
string GetDefaultImageFolder() const { return default_image_folder; }
|
string GetDefaultImageFolder() const { return default_image_folder; }
|
||||||
string SetDefaultImageFolder(const string&);
|
string SetDefaultImageFolder(const string&);
|
||||||
@@ -36,4 +38,5 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
string default_image_folder;
|
string default_image_folder;
|
||||||
|
int depth;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user