Date: Tue, 8 Mar 2022 10:10:03 +0100 Subject: fix "use after free" in QNetworkReplyWasmImplPrivate::doSendRequest() QByteArray must be kept live so constData() returned values for emscripten_fetch call are still lives diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp index 490e2fd8a2..15b7d5d9be 100644 --- a/src/network/access/qnetworkreplywasmimpl.cpp +++ b/src/network/access/qnetworkreplywasmimpl.cpp @@ -209,6 +209,7 @@ void QNetworkReplyWasmImplPrivate::doSendRequest() emscripten_fetch_attr_init(&attr); strcpy(attr.requestMethod, q->methodName().constData()); + QByteArray userName, password; QList headersData = request.rawHeaderList(); int arrayLength = getArraySize(headersData.count()); const char* customHeaders[arrayLength]; @@ -236,8 +237,10 @@ void QNetworkReplyWasmImplPrivate::doSendRequest() // username & password if (!request.url().userInfo().isEmpty()) { - attr.userName = request.url().userName().toUtf8(); - attr.password = request.url().password().toUtf8(); + userName = request.url().userName().toUtf8(); + password = request.url().password().toUtf8(); + attr.userName = userName.constData(); + attr.password = password.constData(); } attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; @@ -265,7 +268,8 @@ void QNetworkReplyWasmImplPrivate::doSendRequest() attr.userData = reinterpret_cast(this); QString dPath = QStringLiteral("/home/web_user/") + request.url().fileName(); - attr.destinationPath = dPath.toUtf8(); + QByteArray destinationPath = dPath.toUtf8(); + attr.destinationPath = destinationPath.constData(); m_fetch = emscripten_fetch(&attr, request.url().toString().toUtf8()); }