mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
Updated error handling
This commit is contained in:
parent
7018ccac64
commit
7a1a2ec328
@ -715,6 +715,11 @@ string SetReservedIds(const string& ids)
|
||||
return "";
|
||||
}
|
||||
|
||||
bool IsValidFilename(const string& filename)
|
||||
{
|
||||
return filename != "." && filename != "..";
|
||||
}
|
||||
|
||||
bool CreateImage(int fd, const PbCommand& command)
|
||||
{
|
||||
string filename = GetParam(command, "file");
|
||||
@ -722,6 +727,10 @@ bool CreateImage(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd, false, "Missing image filename");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(filename)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
||||
}
|
||||
|
||||
string size = GetParam(command, "size");
|
||||
if (size.empty()) {
|
||||
return ReturnStatus(fd, false, "Missing image size");
|
||||
@ -794,6 +803,10 @@ bool DeleteImage(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd, false, "Missing image filename");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(filename)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
||||
}
|
||||
|
||||
if (filename.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The image filename '" + filename + "' must not contain a path");
|
||||
}
|
||||
@ -831,11 +844,19 @@ bool RenameImage(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd, false, "Missing destination filename");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(from)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + from + "'");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(to)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + to + "'");
|
||||
}
|
||||
|
||||
if (from.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The current filename '" + from + "' must not contain a path");
|
||||
return ReturnStatus(fd, false, "The source filename '" + from + "' must not contain a path");
|
||||
}
|
||||
if (to.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The new filename '" + to + "' must not contain a path");
|
||||
return ReturnStatus(fd, false, "The destination filename '" + to + "' must not contain a path");
|
||||
}
|
||||
|
||||
from = default_image_folder + "/" + from;
|
||||
@ -867,11 +888,19 @@ bool CopyImage(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd, false, "Missing destination filename");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(from)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + from + "'");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(to)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + to + "'");
|
||||
}
|
||||
|
||||
if (from.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The current filename '" + from + "' must not contain a path");
|
||||
return ReturnStatus(fd, false, "The source filename '" + from + "' must not contain a path");
|
||||
}
|
||||
if (to.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The new filename '" + to + "' must not contain a path");
|
||||
return ReturnStatus(fd, false, "The destination filename '" + to + "' must not contain a path");
|
||||
}
|
||||
|
||||
from = default_image_folder + "/" + from;
|
||||
@ -921,6 +950,10 @@ bool SetImagePermissions(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd, false, "Missing image filename");
|
||||
}
|
||||
|
||||
if (!IsValidFilename(filename)) {
|
||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
||||
}
|
||||
|
||||
if (filename.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The image filename '" + filename + "' must not contain a path");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user