Add a maximum file size limit when writing to /etc/fstab file.
This commit is contained in:
parent
c9d7e0cd6e
commit
5afe143a19
|
@ -127,15 +127,19 @@ bool ExternalCommandHelper::writeData(QFile& device, const QByteArray& buffer, c
|
|||
return true;
|
||||
}
|
||||
|
||||
/** Creates a new file with given contents.
|
||||
@param fileContents the data that we write
|
||||
/** Creates a new fstab file with given contents.
|
||||
@param Contents the data that we write
|
||||
@return true on success
|
||||
*/
|
||||
bool ExternalCommandHelper::WriteFstab(const QByteArray& fileContents)
|
||||
bool ExternalCommandHelper::WriteFstab(const QByteArray& fstabContents)
|
||||
{
|
||||
if (!isCallerAuthorized()) {
|
||||
return false;
|
||||
}
|
||||
if (fstabContents.size() > MiB) {
|
||||
qCritical() << QStringLiteral("/etc/fstab size limit exceeded.");
|
||||
return false;
|
||||
}
|
||||
QString fstabPath = QStringLiteral("/etc/fstab");
|
||||
QFile fstabFile(fstabPath);
|
||||
|
||||
|
@ -146,7 +150,7 @@ bool ExternalCommandHelper::WriteFstab(const QByteArray& fileContents)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (fstabFile.write(fileContents) != fileContents.size()) {
|
||||
if (fstabFile.write(fstabContents) != fstabContents.size()) {
|
||||
qCritical() << xi18n("Could not write to file <filename>%1</filename>.", fstabPath);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public Q_SLOTS:
|
|||
const QString& targetDevice, const qint64 targetOffset, const qint64 blockSize);
|
||||
Q_SCRIPTABLE QByteArray ReadData(const QString& device, const qint64 offset, const qint64 length);
|
||||
Q_SCRIPTABLE bool WriteData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetOffset);
|
||||
Q_SCRIPTABLE bool WriteFstab(const QByteArray& fileContents);
|
||||
Q_SCRIPTABLE bool WriteFstab(const QByteArray& fstabContents);
|
||||
|
||||
private:
|
||||
bool isCallerAuthorized();
|
||||
|
|
Loading…
Reference in New Issue