Skip to content

Commit

Permalink
implemented addtional command checks to prevent segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
marazmista committed Jan 24, 2019
1 parent 8c57079 commit 992f4b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
36 changes: 32 additions & 4 deletions radeon-profile-daemon/rpdthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void rpdThread::onTimer() {
//
// 4 - start timer with given interval
// 5 - stop timer
// 6 - shared mem key
void rpdThread::performTask(const QString &signal) {
qDebug() << "Performing task: " << signal;

Expand All @@ -71,7 +72,9 @@ void rpdThread::performTask(const QString &signal) {
return;
}

QStringList instructions = signal.split(SEPARATOR, QString::SkipEmptyParts);
QStringList instructions = signal.split(SEPARATOR);
instructions.removeLast();

int size = instructions.size();

// Cycle through instructions
Expand All @@ -84,6 +87,11 @@ void rpdThread::performTask(const QString &signal) {
case SIGNAL_CONFIG:
qDebug() << "Elaborating a CONFIG signal";

if (!checkRequiredCommandLength(1, index, size)) {
qCritical() << "Invalid command! (index out of bounds)";
return;
}

if (!configure(instructions[++index]))
qWarning() << "Configuration failed.";

Expand All @@ -98,9 +106,10 @@ void rpdThread::performTask(const QString &signal) {
// SIGNAL_SET_VALUE + SEPARATOR + VALUE + SEPARATOR + PATH + SEPARATOR
case SIGNAL_SET_VALUE: {
qDebug() << "Elaborating a SET_VALUE signal";
if (index > (size - 1)) {
qWarning() << "Received a SET_VALUE signal with no path: " << signal;
break;

if (!checkRequiredCommandLength(2, index, size)) {
qCritical() << "Invalid command! (index out of bounds)";
return;
}

const QString value = instructions[++index],
Expand All @@ -113,6 +122,12 @@ void rpdThread::performTask(const QString &signal) {
// SIGNAL_TIMER_ON + SEPARATOR + INTERVAL + SEPARATOR
case SIGNAL_TIMER_ON: {
qDebug() << "Elaborating a TIMER_ON signal";

if (!checkRequiredCommandLength(1, index, size)) {
qCritical() << "Invalid command! (index out of bounds)";
return;
}

int inputMillis = instructions[++index].toInt(); // Seconds integer

if (inputMillis < 1) {
Expand All @@ -132,6 +147,12 @@ void rpdThread::performTask(const QString &signal) {
break;

case SIGNAL_SHAREDMEM_KEY: {

if (!checkRequiredCommandLength(1, index, size)) {
qCritical() << "Invalid command! (index out of bounds)";
return;
}

QString key = instructions[++index];
qDebug() << "Shared memory key: " << key;
configureSharedMem(key);
Expand All @@ -145,6 +166,13 @@ void rpdThread::performTask(const QString &signal) {
}
}

bool rpdThread::checkRequiredCommandLength(unsigned required, unsigned currentIndex, unsigned size) {
if (size <= currentIndex + required)
return false;

return true;
}

bool rpdThread::configure(const QString &filePath) {
if (!filePath.startsWith("/sys/kernel/debug/dri/")) {
// The file path is not in whitelisted directories
Expand Down
1 change: 1 addition & 0 deletions radeon-profile-daemon/rpdthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public slots:
void performTask(const QString &signal);
bool configure(const QString &filePath);
void configureSharedMem(const QString &key);
bool checkRequiredCommandLength(unsigned required, unsigned currentIndex, unsigned size);
};

#endif // RPDTHREAD_H

0 comments on commit 992f4b2

Please sign in to comment.