Android: Fix crash caused by unintentionally modification of env data.

The data given to putenv(3) becomes a part of the environment, as
described in SUSv2, so If the data is unintentionally modified or
deleted the consequence can be fatal.
In previous versions of Android, the putenv(3) implementation made a
copy of the data, so this bug has gone unnoticed.

Task-number: QTBUG-39042
Change-Id: I20559c848fded10eeae54c4700ba0f4669fe49fc
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Christian Strømme 2014-05-18 18:45:42 +02:00 committed by The Qt Project
parent 4be7cd09d6
commit 849f8f58ce

View File

@ -463,17 +463,19 @@ static void *startMainMethod(void */*data*/)
static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString)
{
m_mainLibraryHnd = NULL;
const char *nativeString = env->GetStringUTFChars(environmentString, 0);
QByteArray string = nativeString;
env->ReleaseStringUTFChars(environmentString, nativeString);
m_applicationParams=string.split('\t');
foreach (string, m_applicationParams) {
if (!string.isEmpty() && putenv(string.constData()))
qWarning() << "Can't set environment" << string;
{ // Set env. vars
const char *nativeString = env->GetStringUTFChars(environmentString, 0);
const QList<QByteArray> envVars = QByteArray(nativeString).split('\t');
env->ReleaseStringUTFChars(environmentString, nativeString);
foreach (const QByteArray &envVar, envVars) {
const QList<QByteArray> envVarPair = envVar.split('=');
if (envVarPair.size() == 2 && ::setenv(envVarPair[0], envVarPair[1], 1) != 0)
qWarning() << "Can't set environment" << envVarPair;
}
}
nativeString = env->GetStringUTFChars(paramsString, 0);
string = nativeString;
const char *nativeString = env->GetStringUTFChars(paramsString, 0);
QByteArray string = nativeString;
env->ReleaseStringUTFChars(paramsString, nativeString);
m_applicationParams=string.split('\t');