Commit 5afe143a authored by Andrius Štikonas's avatar Andrius Štikonas
Browse files

Add a maximum file size limit when writing to /etc/fstab file.

parent c9d7e0cd
Pipeline #155385 passed with stages
in 1 minute and 13 seconds
......@@ -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);
bool isCallerAuthorized();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment