The m_iconCacheDir variable is used unchecked throughout sni-qt. This may result in deletion of home directory.
This was found by an apparmor "DENIED" while running a sandboxed application (apparmor error data: operation="unlink" name="/home/user/.bash_history").
Lets assume we /tmp writes blocked and we have HOME/.* writes blocked.
1. statusnotifieritemfactory.cpp: FsUtils::generateTempDir is used to generate a temporary IconCache location.
2. fsutils.cpp: Returns an empty QString if generation of file system objects failed.
QString generateTempDir(const QString& prefix)
{
QDir dir = QDir::temp();
if (!dir.mkpath(".")) { qCritical("Failed to generate temporary file for prefix %s: could not create %s", qPrintable(prefix), qPrintable(dir.path()));
return QString();
}
QString tmpl = QString("%1/%2-XXXXXX") .arg(dir.path()) .arg(prefix);
QByteArray ba = QFile::encodeName(tmpl);
const char* name = mkdtemp(ba.data());
if (!name) { qCritical("Failed to generate temporary file for prefix %s: %s", qPrintable(prefix), strerror(errno));
return QString();
}
return QFile::encodeName(name);
}
3. statusnotifieritemfactory.cpp: generateTempDir may have returned an empty QString (or another invalid location), which we are using as m_iconCacheDir
m_iconCache = new IconCache(m_iconCacheDir, this);
[...]
4. iconcache.cpp: IconCache will be created with an empty QString (or another invalid location). If directory creation fails there is an error message printed, but the error stays unchecked.
IconCache::IconCache(const QString& baseDir, QObject* parent)
: QObject(parent)
, m_themePath(baseDir + "/icons")
{
QDir dir(baseDir);
bool ok = dir.mkdir("icons");
if (!ok) { qCritical("Could not create '%s' dir for SNI icon cache", qPrintable(m_themePath));
m_themePath = QString();
return;
}
}
5. statusnotifieritemfactory.cpp: So when closing an application using sni-qt m_iconCacheDir is wiped.
Version: sni-qt_ 0.2.5-0ubuntu1_ amd64
The m_iconCacheDir variable is used unchecked throughout sni-qt. This may result in deletion of home directory.
This was found by an apparmor "DENIED" while running a sandboxed application (apparmor error data: operation="unlink" name="/ home/user/ .bash_history" ).
Lets assume we /tmp writes blocked and we have HOME/.* writes blocked.
1. statusnotifieri temfactory. cpp: FsUtils: :generateTempDi r is used to generate a temporary IconCache location.
[...] temFactory: :StatusNotifier ItemFactory( ) false) "sni-qt_ %1_%2")
.arg(QCoreAppl ication: :applicationFil ePath() .section( '/', -1))
.arg(QCoreAppl ication: :applicationPid ()); :generateTempDi r(tempSubDir) ;
StatusNotifierI
: m_isAvailable(
{
QString tempSubDir = QString(
m_iconCacheDir = FsUtils:
[...]
2. fsutils.cpp: Returns an empty QString if generation of file system objects failed.
QString generateTempDir (const QString& prefix)
qCritical( "Failed to generate temporary file for prefix %s: could not create %s",
qPrintable (prefix) , qPrintable( dir.path( )));
{
QDir dir = QDir::temp();
if (!dir.mkpath(".")) {
return QString();
}
QString tmpl = QString( "%1/%2- XXXXXX" )
.arg(dir. path())
.arg(prefix) ; encodeName( tmpl);
qCritical( "Failed to generate temporary file for prefix %s: %s",
qPrintable (prefix) , strerror(errno)); encodeName( name);
QByteArray ba = QFile::
const char* name = mkdtemp(ba.data());
if (!name) {
return QString();
}
return QFile::
}
3. statusnotifieri temfactory. cpp: generateTempDir may have returned an empty QString (or another invalid location), which we are using as m_iconCacheDir
[...] :generateTempDi r(tempSubDir) ; VAR(m_iconCache Dir);
m_iconCacheDir = FsUtils:
SNI_
m_iconCache = new IconCache( m_iconCacheDir, this);
[...]
4. iconcache.cpp: IconCache will be created with an empty QString (or another invalid location). If directory creation fails there is an error message printed, but the error stays unchecked.
IconCache: :IconCache( const QString& baseDir, QObject* parent)
qCritical( "Could not create '%s' dir for SNI icon cache", qPrintable( m_themePath) );
: QObject(parent)
, m_themePath(baseDir + "/icons")
{
QDir dir(baseDir);
bool ok = dir.mkdir("icons");
if (!ok) {
m_themePath = QString();
return;
}
}
5. statusnotifieri temfactory. cpp: So when closing an application using sni-qt m_iconCacheDir is wiped.
StatusNotifier ItemFactory: :~StatusNotifie rItemFactory( ) :recursiveRm( m_iconCacheDir) ;
{
SNI_DEBUG;
FsUtils:
}