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.master
parent
26e069d6cd
commit
83a865411d
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue