diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-05-02 13:37:33 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-05-02 13:37:33 (GMT) |
commit | 443608952d7df9a5146317be992320ba232d2cf9 (patch) | |
tree | 1d14fd075d894af327bae9ca37ee03bb6f624cbd /src | |
parent | eb61f612fea1b76fe01ee237e5bd160f66aeca3d (diff) | |
download | Qt-443608952d7df9a5146317be992320ba232d2cf9.zip Qt-443608952d7df9a5146317be992320ba232d2cf9.tar.gz Qt-443608952d7df9a5146317be992320ba232d2cf9.tar.bz2 |
fix potential crash in QProcessEnvironment::systemEnvironment() on windows
GetEnvironmentStrings() can theoretically return null
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 7739bbd..0c8becc 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -283,18 +283,19 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment() QProcessEnvironment env; // Calls to setenv() affect the low-level environment as well. // This is not the case the other way round. - wchar_t *envStrings = GetEnvironmentStringsW(); - for (const wchar_t *entry = envStrings; *entry; ) { - int entryLen = wcslen(entry); - if (const wchar_t *equal = wcschr(entry, L'=')) { - int nameLen = equal - entry; - QString name = QString::fromWCharArray(entry, nameLen); - QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1); - env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value); + if (wchar_t *envStrings = GetEnvironmentStringsW()) { + for (const wchar_t *entry = envStrings; *entry; ) { + int entryLen = wcslen(entry); + if (const wchar_t *equal = wcschr(entry, L'=')) { + int nameLen = equal - entry; + QString name = QString::fromWCharArray(entry, nameLen); + QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1); + env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value); + } + entry += entryLen + 1; } - entry += entryLen + 1; + FreeEnvironmentStrings(envStrings); } - FreeEnvironmentStrings(envStrings); return env; } |