diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index 9bb01ec..a2ab6da 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -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 %1.", fstabPath); return false; } diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h index 0954e8e..e3c6931 100644 --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -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();