summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qenvironmentvariables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qenvironmentvariables.cpp')
-rw-r--r--src/corelib/global/qenvironmentvariables.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/global/qenvironmentvariables.cpp b/src/corelib/global/qenvironmentvariables.cpp
index 71544ae56c..d3d963e52e 100644
--- a/src/corelib/global/qenvironmentvariables.cpp
+++ b/src/corelib/global/qenvironmentvariables.cpp
@@ -262,6 +262,14 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept
*/
bool qputenv(const char *varName, const QByteArray &value)
{
+ // protect against non-NUL-terminated QByteArrays:
+ if (!const_cast<QByteArray&>(value).data_ptr()->isMutable()) {
+ QByteArray copy(value);
+ copy.reserve(copy.size() + 1); // ensures NUL termination (and isMutable() even for size==0
+ // (unlike detach()) to avoid infinite recursion)
+ return qputenv(varName, copy);
+ }
+
#if defined(Q_CC_MSVC)
const auto locker = qt_scoped_lock(environmentMutex);
return _putenv_s(varName, value.constData()) == 0;