QCoreApplication::applicationFilePath: don't check for existence twice
A file that doesn't exist can't have a canonical path, so we don't need to check fi.exists() before calling fi.canonicalFilePath(). Also avoids a TOCTOU mistake: if the exists() returned true, we would store whatever canonicalFilePath() returned, even an empty string (which can also happen if realpath(3) fails for some reason). Change-Id: I7a386ad4f0cb4e2ba629fffd16789aaa8367e641 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
parent
ccd47237ee
commit
21b123f888
@ -2332,18 +2332,9 @@ QString QCoreApplication::applicationFilePath()
|
|||||||
if (QCoreApplicationPrivate::cachedApplicationFilePath)
|
if (QCoreApplicationPrivate::cachedApplicationFilePath)
|
||||||
return *QCoreApplicationPrivate::cachedApplicationFilePath;
|
return *QCoreApplicationPrivate::cachedApplicationFilePath;
|
||||||
|
|
||||||
QString qAppFileName_str = qAppFileName();
|
QString absPath = qAppFileName();
|
||||||
if (!qAppFileName_str.isEmpty()) {
|
if (absPath.isEmpty() && !arguments().isEmpty()) {
|
||||||
QFileInfo fi(qAppFileName_str);
|
|
||||||
if (fi.exists()) {
|
|
||||||
QCoreApplicationPrivate::setApplicationFilePath(fi.canonicalFilePath());
|
|
||||||
return *QCoreApplicationPrivate::cachedApplicationFilePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!arguments().isEmpty()) {
|
|
||||||
QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit());
|
QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit());
|
||||||
QString absPath;
|
|
||||||
|
|
||||||
if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
|
if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) {
|
||||||
/*
|
/*
|
||||||
@ -2366,14 +2357,13 @@ QString QCoreApplication::applicationFilePath()
|
|||||||
}
|
}
|
||||||
|
|
||||||
absPath = QDir::cleanPath(absPath);
|
absPath = QDir::cleanPath(absPath);
|
||||||
|
|
||||||
QFileInfo fi(absPath);
|
|
||||||
if (fi.exists()) {
|
|
||||||
QCoreApplicationPrivate::setApplicationFilePath(fi.canonicalFilePath());
|
|
||||||
return *QCoreApplicationPrivate::cachedApplicationFilePath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absPath = QFileInfo(absPath).canonicalFilePath();
|
||||||
|
if (!absPath.isEmpty()) {
|
||||||
|
QCoreApplicationPrivate::setApplicationFilePath(absPath);
|
||||||
|
return *QCoreApplicationPrivate::cachedApplicationFilePath;
|
||||||
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user