From 9e359c98a9f1ef5620fa9a7e8097b99b5c6c0e17 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 4 Oct 2019 17:43:48 +0200 Subject: [PATCH] [machineid] Refactor workers, demand absolute paths --- src/modules/machineid/Workers.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index e7d5eb03f..6b55f2489 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -29,16 +29,34 @@ namespace MachineId { +static inline bool +isAbsolutePath( const QString& fileName ) +{ + return fileName.startsWith( '/' ); +} + // might need to use a helper to remove the file void removeFile( const QString& rootMountPoint, const QString& fileName ) { - QFile::remove( rootMountPoint + fileName ); + if ( isAbsolutePath( fileName ) ) + { + QFile::remove( rootMountPoint + fileName ); + } + // Otherwise, do nothing } Calamares::JobResult copyFile( const QString& rootMountPoint, const QString& fileName ) { + if ( !isAbsolutePath( fileName ) ) + { + return Calamares::JobResult::internalError( + QObject::tr( "File not found" ), + QObject::tr( "Path
%1
must be an absolute path." ).arg( fileName ), + 0 ); + } + QFile f( fileName ); if ( !f.exists() ) {