diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-10-22 12:35:08 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-10-22 12:40:18 +0000 |
commit | 8848abe69fa957d5406659229cecdada83da8421 (patch) | |
tree | bec001ed4f959735e5371c1e5b4a55b4784e59c8 /src/qml/qml | |
parent | bef2dc8a236d4062f6b05b10cf99e6d081e4d6ce (diff) |
QML: Sanitize reading environment variables.
Where possible, use qEnvironmentVariableIsSet()/
qEnvironmentVariableIsEmpty() instead of checking on the
return value of qgetenv().
Where the value is required, add a check using one of
qEnvironmentVariableIsSet()/Empty().
Change-Id: Ia8b7534e6f5165bd8a6b4e63ccc139c42dd03056
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlglobal_p.h | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index b7212648ab..23cfc24e7a 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -59,10 +59,12 @@ QT_BEGIN_NAMESPACE { \ static enum { Yes, No, Unknown } status = Unknown; \ if (status == Unknown) { \ - QByteArray v = qgetenv(#var); \ - bool value = !v.isEmpty() && v != "0" && v != "false"; \ - if (value) status = Yes; \ - else status = No; \ + status = No; \ + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(#var))) { \ + const QByteArray v = qgetenv(#var); \ + if (v != "0" && v != "false") \ + status = Yes; \ + } \ } \ return status == Yes; \ } diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 8f73732615..f6f8c6e51e 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1562,8 +1562,8 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e) addImportPath(installImportsPath); // env import paths - QByteArray envImportPath = qgetenv("QML2_IMPORT_PATH"); - if (!envImportPath.isEmpty()) { + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QML2_IMPORT_PATH"))) { + const QByteArray envImportPath = qgetenv("QML2_IMPORT_PATH"); #if defined(Q_OS_WIN) QLatin1Char pathSep(';'); #else |