forked from jbagg/QtZeroConf
Android: Fix missing or corrupt service name
The publish service name and type are passed to startServicePublish() as char pointers. startServicePublish() calls runOnAndroidThread which asks the java code to run registerService(). If name and type are objects on the stack, they could get freed / deleted before the registerService() is run in the java thread which would cause registerService() to use deleted objects. Fix --> make permanent objects for name and type.
This commit is contained in:
@ -77,6 +77,8 @@ QZeroConfPrivate::~QZeroConfPrivate()
|
|||||||
void QZeroConfPrivate::startServicePublish(const char *name, const char *type, quint16 port)
|
void QZeroConfPrivate::startServicePublish(const char *name, const char *type, quint16 port)
|
||||||
{
|
{
|
||||||
QAndroidJniObject ref(nsdManager);
|
QAndroidJniObject ref(nsdManager);
|
||||||
|
publishName = name;
|
||||||
|
publishType = type;
|
||||||
QtAndroid::runOnAndroidThread([=](){
|
QtAndroid::runOnAndroidThread([=](){
|
||||||
QAndroidJniObject txtMap("java/util/HashMap");
|
QAndroidJniObject txtMap("java/util/HashMap");
|
||||||
foreach (const QByteArray &key, txtRecords.keys()) {
|
foreach (const QByteArray &key, txtRecords.keys()) {
|
||||||
@ -86,8 +88,8 @@ void QZeroConfPrivate::startServicePublish(const char *name, const char *type, q
|
|||||||
}
|
}
|
||||||
|
|
||||||
ref.callMethod<void>("registerService", "(Ljava/lang/String;Ljava/lang/String;ILjava/util/Map;)V",
|
ref.callMethod<void>("registerService", "(Ljava/lang/String;Ljava/lang/String;ILjava/util/Map;)V",
|
||||||
QAndroidJniObject::fromString(QString(name)).object<jstring>(),
|
QAndroidJniObject::fromString(publishName).object<jstring>(),
|
||||||
QAndroidJniObject::fromString(QString(type)).object<jstring>(),
|
QAndroidJniObject::fromString(publishType).object<jstring>(),
|
||||||
port,
|
port,
|
||||||
txtMap.object());
|
txtMap.object());
|
||||||
});
|
});
|
||||||
|
@ -54,6 +54,8 @@ public:
|
|||||||
bool browserExists = false;
|
bool browserExists = false;
|
||||||
bool publisherExists = false;
|
bool publisherExists = false;
|
||||||
QMap<QByteArray, QByteArray> txtRecords;
|
QMap<QByteArray, QByteArray> txtRecords;
|
||||||
|
QString publishName;
|
||||||
|
QString publishType;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
Reference in New Issue
Block a user