From 2e91730f7a428cff81443c66613570259180c173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 14 Nov 2020 00:55:29 +0000 Subject: [PATCH] Fix parsing fstab mountpoints when they contain spaces or tabs. If the name of the mount point contains spaces or tabs these can be escaped as `\040' and '\011' respectively. BUG: 428932 --- src/core/fstab.cpp | 20 ++++++++++++++++++-- src/core/fstab.h | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/fstab.cpp b/src/core/fstab.cpp index 196deca..94f6534 100644 --- a/src/core/fstab.cpp +++ b/src/core/fstab.cpp @@ -83,7 +83,7 @@ FstabEntryList readFstabEntries( const QString& fstabPath ) // (5) pass number (optional, defaults to 0), no comment is allowed if omitted, // (#) comment (optional). auto fsSpec = splitLine.at(0); - auto mountPoint = splitLine.at(1); + auto mountPoint = unescapeSpaces(splitLine.at(1)); auto fsType = splitLine.at(2); auto options = splitLine.at(3); @@ -110,6 +110,22 @@ FstabEntryList readFstabEntries( const QString& fstabPath ) return fstabEntries; } +QString escapeSpaces(const QString& mountPoint) +{ + QString tmp = mountPoint; + tmp.replace(QStringLiteral(" "), QStringLiteral("\\040")); + tmp.replace(QStringLiteral("\t"), QStringLiteral("\\011")); + return tmp; +} + +QString unescapeSpaces(const QString& mountPoint) +{ + QString tmp = mountPoint; + tmp.replace(QStringLiteral("\\040"), QStringLiteral(" ")); + tmp.replace(QStringLiteral("\\011"), QStringLiteral("\t")); + return tmp; +} + void FstabEntry::setFsSpec(const QString& s) { d->m_fsSpec = s; @@ -262,7 +278,7 @@ static void writeEntry(QTextStream& s, const FstabEntry& entry, std::array FstabEntryList; +QString escapeSpaces(const QString& mountPoint); +QString unescapeSpaces(const QString& mountPoint); + LIBKPMCORE_EXPORT FstabEntryList readFstabEntries(const QString& fstabPath = QStringLiteral("/etc/fstab")); LIBKPMCORE_EXPORT QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath = QStringLiteral("/etc/fstab")); LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename = QStringLiteral("/etc/fstab"));