From: Shane Kearns Date: Thu, 23 Feb 2012 15:57:15 +0000 (+0000) Subject: Fix buffer overrun crash running MSVC2010 win32 Qt on win64 X-Git-Tag: qt-v5.0.0-alpha1~642 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=762a721f7f544f2428111f70f4d388f2d4134a55;p=profile%2Fivi%2Fqtbase.git Fix buffer overrun crash running MSVC2010 win32 Qt on win64 When loading dnsapi.dll as a plugin, we experience crashes because the calling convention is not specified. The default is _cdecl, but __stdcall (via the WINAPI macro) should be used for windows APIs. Mismatched calling convention results in corruption of local variables, probably because the stack pointer is incorrect and SP offsets are used in optimised builds rather than frame pointer offsets. Since the library has been available since Windows 2000, I don't think that we need to load it dynamically. (Unlike the unix version where it isn't part of the LSB) Also checked that the current release of mingw works. Task-number: QTBUG-24227 Change-Id: I37c0a6aa0c133799c2a6dd9391ca1435ba2539ea Reviewed-by: Friedemann Kleint --- diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri index adc72bbc..a5508af 100644 --- a/src/network/kernel/kernel.pri +++ b/src/network/kernel/kernel.pri @@ -29,6 +29,7 @@ unix:SOURCES += kernel/qdnslookup_unix.cpp kernel/qhostinfo_unix.cpp kernel/qnet win32: { HEADERS += kernel/qnetworkinterface_win_p.h SOURCES += kernel/qdnslookup_win.cpp kernel/qhostinfo_win.cpp kernel/qnetworkinterface_win.cpp + LIBS += -ldnsapi } integrity:SOURCES += kernel/qdnslookup_unix.cpp kernel/qhostinfo_unix.cpp kernel/qnetworkinterface_unix.cpp diff --git a/src/network/kernel/qdnslookup_win.cpp b/src/network/kernel/qdnslookup_win.cpp index 9b2c088..e7aaf29 100644 --- a/src/network/kernel/qdnslookup_win.cpp +++ b/src/network/kernel/qdnslookup_win.cpp @@ -44,46 +44,17 @@ #include #include -#include #include #include QT_BEGIN_NAMESPACE -typedef DNS_STATUS (*dns_query_utf8_proto)(PCSTR,WORD,DWORD,PIP4_ARRAY,PDNS_RECORD*,PVOID*); -static dns_query_utf8_proto local_dns_query_utf8 = 0; -typedef void (*dns_record_list_free_proto)(PDNS_RECORD,DNS_FREE_TYPE); -static dns_record_list_free_proto local_dns_record_list_free = 0; - -static void resolveLibrary() -{ - local_dns_query_utf8 = (dns_query_utf8_proto) QSystemLibrary::resolve(QLatin1String("dnsapi"), "DnsQuery_UTF8"); - local_dns_record_list_free = (dns_record_list_free_proto) QSystemLibrary::resolve(QLatin1String("dnsapi"), "DnsRecordListFree"); -} - void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply) { - // Load DnsQuery_UTF8 and DnsRecordListFree on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_dns_query_utf8)); - if (!triedResolve) { - resolveLibrary(); - triedResolve = true; - } - } - - // If DnsQuery_UTF8 or DnsRecordListFree is missing, fail. - if (!local_dns_query_utf8 || !local_dns_record_list_free) { - reply->error = QDnsLookup::ResolverError, - reply->errorString = tr("Resolver functions not found"); - return; - } - // Perform DNS query. - PDNS_RECORD dns_records; - const DNS_STATUS status = local_dns_query_utf8(requestName, requestType, DNS_QUERY_STANDARD, NULL, &dns_records, NULL); + PDNS_RECORD dns_records = 0; + const DNS_STATUS status = DnsQuery_UTF8(requestName, requestType, DNS_QUERY_STANDARD, NULL, &dns_records, NULL); switch (status) { case ERROR_SUCCESS: break; @@ -172,7 +143,7 @@ void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestN } } - local_dns_record_list_free(dns_records, DnsFreeRecordList); + DnsRecordListFree(dns_records, DnsFreeRecordList); } QT_END_NAMESPACE