Commit 83a86541 authored by Andrius Štikonas's avatar Andrius Štikonas
Browse files

ExternalCommandHelper::ReadData should not follow symlinks.

Resolve all symlinks in the userspace application and make sure
that helper only deals with root owned path in /dev but not in
/dev/shm.
parent 26e069d6
Pipeline #192951 passed with stage
in 1 minute and 8 seconds
......@@ -193,7 +193,9 @@ QByteArray ExternalCommand::readData(const CopySourceDevice& source)
if (!interface)
return {};
QDBusPendingCall pcall = interface->ReadData(source.path(), source.firstByte(), source.length());
// Helper is restricted not to resolve symlinks
QFileInfo sourceInfo(source.path());
QDBusPendingCall pcall = interface->ReadData(sourceInfo.canonicalFilePath(), source.firstByte(), source.length());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
......
......@@ -304,6 +304,17 @@ QByteArray ExternalCommandHelper::ReadData(const QString& device, const qint64 o
return {};
}
// Do not follow symlinks
QFileInfo info(device);
if (info.isSymbolicLink()) {
qWarning() << "ReadData: device should not be symbolic link";
return {};
}
if (device.left(5) != QStringLiteral("/dev/") || device.left(9) != QStringLiteral("/dev/shm/")) {
qWarning() << "Error: trying to read data from device not in /dev";
return {};
}
QByteArray buffer;
QFile sourceDevice(device);
bool rval = readData(sourceDevice, buffer, offset, length);
......
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