Browse Source

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
release/20.12
Andrius Štikonas 3 months ago
parent
commit
2e91730f7a
2 changed files with 21 additions and 2 deletions
  1. +18
    -2
      src/core/fstab.cpp
  2. +3
    -0
      src/core/fstab.h

+ 18
- 2
src/core/fstab.cpp View File

@ -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<unsig
s.setFieldAlignment(QTextStream::AlignLeft);
s.setFieldWidth(columnWidth[0]);
s << entry.fsSpec()
<< qSetFieldWidth(columnWidth[1]) << (entry.mountPoint().isEmpty() ? QStringLiteral("none") : entry.mountPoint())
<< qSetFieldWidth(columnWidth[1]) << (entry.mountPoint().isEmpty() ? QStringLiteral("none") : escapeSpaces(entry.mountPoint()))
<< qSetFieldWidth(columnWidth[2]) << entry.type()
<< qSetFieldWidth(columnWidth[3]) << entry.optionsString() << qSetFieldWidth(0)
<< entry.dumpFreq() << " "


+ 3
- 0
src/core/fstab.h View File

@ -111,6 +111,9 @@ private:
typedef QList<FstabEntry> 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"));


Loading…
Cancel
Save