| File: | var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp |
| Warning: | line 120, column 16 Value stored to 'rectype' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include "TRRQuery.h" |
| 6 | |
| 7 | #include "mozilla/StaticPrefs_network.h" |
| 8 | #include "mozilla/Telemetry.h" |
| 9 | #include "nsQueryObject.h" |
| 10 | #include "TRR.h" |
| 11 | #include "TRRService.h" |
| 12 | // Put DNSLogging.h at the end to avoid LOG being overwritten by other headers. |
| 13 | #include "DNSLogging.h" |
| 14 | |
| 15 | namespace mozilla { |
| 16 | namespace net { |
| 17 | |
| 18 | static already_AddRefed<AddrInfo> merge_rrset(AddrInfo* rrto, |
| 19 | AddrInfo* rrfrom) { |
| 20 | MOZ_ASSERT(rrto && rrfrom)do { static_assert( mozilla::detail::AssertionConditionType< decltype(rrto && rrfrom)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(rrto && rrfrom))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("rrto && rrfrom" , "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 20); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rrto && rrfrom" ")"); do { *((volatile int*)__null) = 20; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 21 | // Each of the arguments are all-IPv4 or all-IPv6 hence judging |
| 22 | // by the first element. This is true only for TRR resolutions. |
| 23 | bool isIPv6 = rrfrom->Addresses().Length() > 0 && |
| 24 | rrfrom->Addresses()[0].raw.family == PR_AF_INET610; |
| 25 | |
| 26 | nsTArray<NetAddr> addresses; |
| 27 | if (isIPv6) { |
| 28 | addresses = rrfrom->Addresses().Clone(); |
| 29 | addresses.AppendElements(rrto->Addresses()); |
| 30 | } else { |
| 31 | addresses = rrto->Addresses().Clone(); |
| 32 | addresses.AppendElements(rrfrom->Addresses()); |
| 33 | } |
| 34 | auto builder = rrto->Build(); |
| 35 | builder.SetAddresses(std::move(addresses)); |
| 36 | return builder.Finish(); |
| 37 | } |
| 38 | |
| 39 | void TRRQuery::Cancel(nsresult aStatus) { |
| 40 | MutexAutoLock trrlock(mTrrLock); |
| 41 | if (mTrrA) { |
| 42 | mTrrA->Cancel(aStatus); |
| 43 | } |
| 44 | if (mTrrAAAA) { |
| 45 | mTrrAAAA->Cancel(aStatus); |
| 46 | } |
| 47 | if (mTrrByType) { |
| 48 | mTrrByType->Cancel(aStatus); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void TRRQuery::MarkSendingTRR(TRR* trr, enum TrrType rectype, MutexAutoLock&) { |
| 53 | if (rectype == TRRTYPE_A) { |
| 54 | MOZ_ASSERT(!mTrrA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mTrrA)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(!mTrrA))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mTrrA", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 54); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrrA" ")"); do { *((volatile int*)__null) = 54; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 55 | mTrrA = trr; |
| 56 | mTrrAUsed = STARTED; |
| 57 | } else if (rectype == TRRTYPE_AAAA) { |
| 58 | MOZ_ASSERT(!mTrrAAAA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mTrrAAAA)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mTrrAAAA))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mTrrAAAA", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 58); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrrAAAA" ")" ); do { *((volatile int*)__null) = 58; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 59 | mTrrAAAA = trr; |
| 60 | mTrrAAAAUsed = STARTED; |
| 61 | } else { |
| 62 | LOG(("TrrLookup called with bad type set: %d\n", rectype))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TrrLookup called with bad type set: %d\n", rectype); } } while (0); |
| 63 | MOZ_ASSERT(0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(0)>::isValid, "invalid assertion condition"); if ( (__builtin_expect(!!(!(!!(0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("0", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 63); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0" ")"); do { *((volatile int*)__null) = 63; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void TRRQuery::PrepareQuery(enum TrrType aRecType, |
| 68 | nsTArray<RefPtr<TRR>>& aRequestsToSend) { |
| 69 | LOG(("TRR Resolve %s type %d\n", mRecord->host.get(), (int)aRecType))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRR Resolve %s type %d\n", mRecord->host.get(), (int)aRecType ); } } while (0); |
| 70 | RefPtr<TRR> trr = new TRR(this, mRecord, aRecType); |
| 71 | |
| 72 | { |
| 73 | MutexAutoLock trrlock(mTrrLock); |
| 74 | MarkSendingTRR(trr, aRecType, trrlock); |
| 75 | aRequestsToSend.AppendElement(trr); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | bool TRRQuery::SendQueries(nsTArray<RefPtr<TRR>>& aRequestsToSend) { |
| 80 | bool madeQuery = false; |
| 81 | mTRRRequestCounter = aRequestsToSend.Length(); |
| 82 | for (const auto& request : aRequestsToSend) { |
| 83 | if (NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(request))((bool)(__builtin_expect(!!(!NS_FAILED_impl(TRRService::Get() ->DispatchTRRRequest(request))), 1)))) { |
| 84 | madeQuery = true; |
| 85 | } else { |
| 86 | mTRRRequestCounter--; |
| 87 | MutexAutoLock trrlock(mTrrLock); |
| 88 | if (request == mTrrA) { |
| 89 | mTrrA = nullptr; |
| 90 | mTrrAUsed = INIT; |
| 91 | } |
| 92 | if (request == mTrrAAAA) { |
| 93 | mTrrAAAA = nullptr; |
| 94 | mTrrAAAAUsed = INIT; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | aRequestsToSend.Clear(); |
| 99 | return madeQuery; |
| 100 | } |
| 101 | |
| 102 | nsresult TRRQuery::DispatchLookup(TRR* pushedTRR) { |
| 103 | mTrrStart = TimeStamp::Now(); |
| 104 | |
| 105 | if (!mRecord->IsAddrRecord()) { |
| 106 | return DispatchByTypeLookup(pushedTRR); |
| 107 | } |
| 108 | |
| 109 | RefPtr<AddrHostRecord> addrRec = do_QueryObject(mRecord); |
| 110 | MOZ_ASSERT(addrRec)do { static_assert( mozilla::detail::AssertionConditionType< decltype(addrRec)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(addrRec))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("addrRec", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 110); AnnotateMozCrashReason("MOZ_ASSERT" "(" "addrRec" ")" ); do { *((volatile int*)__null) = 110; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 111 | if (!addrRec) { |
| 112 | return NS_ERROR_UNEXPECTED; |
| 113 | } |
| 114 | |
| 115 | mTrrAUsed = INIT; |
| 116 | mTrrAAAAUsed = INIT; |
| 117 | |
| 118 | // Always issue both A and AAAA. |
| 119 | // When both are complete we filter out the unneeded results. |
| 120 | enum TrrType rectype = (mRecord->af == AF_INET610) ? TRRTYPE_AAAA : TRRTYPE_A; |
Value stored to 'rectype' during its initialization is never read | |
| 121 | |
| 122 | if (pushedTRR) { |
| 123 | MutexAutoLock trrlock(mTrrLock); |
| 124 | rectype = pushedTRR->Type(); |
| 125 | MarkSendingTRR(pushedTRR, rectype, trrlock); |
| 126 | return NS_OK; |
| 127 | } |
| 128 | |
| 129 | // Need to dispatch TRR requests after |mTrrA| and |mTrrAAAA| are set |
| 130 | // properly so as to avoid the race when CompleteLookup() is called at the |
| 131 | // same time. |
| 132 | nsTArray<RefPtr<TRR>> requestsToSend; |
| 133 | if ((mRecord->af == AF_UNSPEC0 || mRecord->af == AF_INET610) && |
| 134 | !StaticPrefs::network_dns_disableIPv6()) { |
| 135 | PrepareQuery(TRRTYPE_AAAA, requestsToSend); |
| 136 | } |
| 137 | if (mRecord->af == AF_UNSPEC0 || mRecord->af == AF_INET2) { |
| 138 | PrepareQuery(TRRTYPE_A, requestsToSend); |
| 139 | } |
| 140 | |
| 141 | if (SendQueries(requestsToSend)) { |
| 142 | return NS_OK; |
| 143 | } |
| 144 | |
| 145 | return NS_ERROR_UNKNOWN_HOST; |
| 146 | } |
| 147 | |
| 148 | nsresult TRRQuery::DispatchByTypeLookup(TRR* pushedTRR) { |
| 149 | RefPtr<TypeHostRecord> typeRec = do_QueryObject(mRecord); |
| 150 | MOZ_ASSERT(typeRec)do { static_assert( mozilla::detail::AssertionConditionType< decltype(typeRec)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(typeRec))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("typeRec", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 150); AnnotateMozCrashReason("MOZ_ASSERT" "(" "typeRec" ")" ); do { *((volatile int*)__null) = 150; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 151 | if (!typeRec) { |
| 152 | return NS_ERROR_UNEXPECTED; |
| 153 | } |
| 154 | |
| 155 | enum TrrType rectype; |
| 156 | |
| 157 | // XXX this could use a more extensible approach. |
| 158 | if (mRecord->type == nsIDNSService::RESOLVE_TYPE_TXT) { |
| 159 | rectype = TRRTYPE_TXT; |
| 160 | } else if (mRecord->type == nsIDNSService::RESOLVE_TYPE_HTTPSSVC) { |
| 161 | rectype = TRRTYPE_HTTPSSVC; |
| 162 | } else if (pushedTRR) { |
| 163 | rectype = pushedTRR->Type(); |
| 164 | } else { |
| 165 | MOZ_ASSERT(false, "Not an expected request type")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Not an expected request type" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Not an expected request type" ")"); do { *((volatile int*)__null ) = 165; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 166 | return NS_ERROR_UNKNOWN_HOST; |
| 167 | } |
| 168 | |
| 169 | LOG(("TRR Resolve %s type %d\n", typeRec->host.get(), (int)rectype))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRR Resolve %s type %d\n", typeRec->host.get(), (int)rectype ); } } while (0); |
| 170 | RefPtr<TRR> trr = pushedTRR ? pushedTRR : new TRR(this, mRecord, rectype); |
| 171 | |
| 172 | if (pushedTRR || NS_SUCCEEDED(TRRService::Get()->DispatchTRRRequest(trr))((bool)(__builtin_expect(!!(!NS_FAILED_impl(TRRService::Get() ->DispatchTRRRequest(trr))), 1)))) { |
| 173 | MutexAutoLock trrlock(mTrrLock); |
| 174 | MOZ_ASSERT(!mTrrByType)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mTrrByType)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mTrrByType))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mTrrByType", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 174); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrrByType" ")"); do { *((volatile int*)__null) = 174; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 175 | mTrrByType = trr; |
| 176 | return NS_OK; |
| 177 | } |
| 178 | |
| 179 | return NS_ERROR_UNKNOWN_HOST; |
| 180 | } |
| 181 | |
| 182 | AHostResolver::LookupStatus TRRQuery::CompleteLookup( |
| 183 | nsHostRecord* rec, nsresult status, AddrInfo* aNewRRSet, bool pb, |
| 184 | const nsACString& aOriginsuffix, nsHostRecord::TRRSkippedReason aReason, |
| 185 | TRR* aTRRRequest) { |
| 186 | if (rec != mRecord) { |
| 187 | LOG(("TRRQuery::CompleteLookup - Pushed record. Go to resolver"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRRQuery::CompleteLookup - Pushed record. Go to resolver") ; } } while (0); |
| 188 | return mHostResolver->CompleteLookup(rec, status, aNewRRSet, pb, |
| 189 | aOriginsuffix, aReason, aTRRRequest); |
| 190 | } |
| 191 | |
| 192 | LOG(("TRRQuery::CompleteLookup > host: %s", rec->host.get()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRRQuery::CompleteLookup > host: %s", rec->host.get( )); } } while (0); |
| 193 | |
| 194 | RefPtr<AddrInfo> newRRSet(aNewRRSet); |
| 195 | DNSResolverType resolverType = newRRSet->ResolverType(); |
| 196 | { |
| 197 | MutexAutoLock trrlock(mTrrLock); |
| 198 | if (newRRSet->TRRType() == TRRTYPE_A) { |
| 199 | MOZ_ASSERT(mTrrA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mTrrA)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(mTrrA))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("mTrrA", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 199); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mTrrA" ")"); do { *((volatile int*)__null) = 199; __attribute__((nomerge) ) ::abort(); } while (false); } } while (false); |
| 200 | mTRRAFailReason = aReason; |
| 201 | mTrrA = nullptr; |
| 202 | mTrrAUsed = NS_SUCCEEDED(status)((bool)(__builtin_expect(!!(!NS_FAILED_impl(status)), 1))) ? OK : FAILED; |
| 203 | MOZ_ASSERT(!mAddrInfoA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mAddrInfoA)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mAddrInfoA))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mAddrInfoA", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 203); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mAddrInfoA" ")"); do { *((volatile int*)__null) = 203; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 204 | mAddrInfoA = newRRSet; |
| 205 | mAResult = status; |
| 206 | LOG(("A query status: 0x%x", static_cast<uint32_t>(status)))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "A query status: 0x%x", static_cast<uint32_t>(status) ); } } while (0); |
| 207 | } else if (newRRSet->TRRType() == TRRTYPE_AAAA) { |
| 208 | MOZ_ASSERT(mTrrAAAA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mTrrAAAA)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mTrrAAAA))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mTrrAAAA", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 208); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mTrrAAAA" ")" ); do { *((volatile int*)__null) = 208; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 209 | mTRRAAAAFailReason = aReason; |
| 210 | mTrrAAAA = nullptr; |
| 211 | mTrrAAAAUsed = NS_SUCCEEDED(status)((bool)(__builtin_expect(!!(!NS_FAILED_impl(status)), 1))) ? OK : FAILED; |
| 212 | MOZ_ASSERT(!mAddrInfoAAAA)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mAddrInfoAAAA)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mAddrInfoAAAA))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mAddrInfoAAAA" , "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 212); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mAddrInfoAAAA" ")"); do { *((volatile int*)__null) = 212; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 213 | mAddrInfoAAAA = newRRSet; |
| 214 | mAAAAResult = status; |
| 215 | LOG(("AAAA query status: 0x%x", static_cast<uint32_t>(status)))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "AAAA query status: 0x%x", static_cast<uint32_t>(status )); } } while (0); |
| 216 | } else { |
| 217 | MOZ_ASSERT(0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(0)>::isValid, "invalid assertion condition"); if ( (__builtin_expect(!!(!(!!(0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("0", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 217); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0" ")"); do { *((volatile int*)__null) = 217; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (NS_SUCCEEDED(status)((bool)(__builtin_expect(!!(!NS_FAILED_impl(status)), 1)))) { |
| 222 | mTRRSuccess++; |
| 223 | if (mTRRSuccess == 1) { |
| 224 | // Store the duration on first succesful TRR response. We |
| 225 | // don't know that there will be a second response nor can we |
| 226 | // tell which of two has useful data. |
| 227 | mTrrDuration = TimeStamp::Now() - mTrrStart; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | bool pendingRequest = false; |
| 232 | if (mTRRRequestCounter) { |
| 233 | mTRRRequestCounter--; |
| 234 | pendingRequest = (mTRRRequestCounter != 0); |
| 235 | } else { |
| 236 | MOZ_DIAGNOSTIC_CRASH("Request counter is messed up")do { do { } while (false); MOZ_ReportCrash("" "Request counter is messed up" , "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 236); AnnotateMozCrashReason("MOZ_CRASH(" "Request counter is messed up" ")"); do { *((volatile int*)__null) = 236; __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 237 | } |
| 238 | if (pendingRequest) { // There are other outstanding requests |
| 239 | LOG(("CompleteLookup: waiting for all responses!\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "CompleteLookup: waiting for all responses!\n"); } } while ( 0); |
| 240 | return LOOKUP_OK; |
| 241 | } |
| 242 | |
| 243 | if (mRecord->af == AF_UNSPEC0) { |
| 244 | // merge successful records |
| 245 | if (mTrrAUsed == OK) { |
| 246 | LOG(("Have A response"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "Have A response"); } } while (0); |
| 247 | newRRSet = mAddrInfoA; |
| 248 | status = mAResult; |
| 249 | if (mTrrAAAAUsed == OK) { |
| 250 | LOG(("Merging A and AAAA responses"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "Merging A and AAAA responses"); } } while (0); |
| 251 | newRRSet = merge_rrset(newRRSet, mAddrInfoAAAA); |
| 252 | } |
| 253 | } else { |
| 254 | newRRSet = mAddrInfoAAAA; |
| 255 | status = mAAAAResult; |
| 256 | } |
| 257 | |
| 258 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0))) && (mAAAAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST || |
| 259 | mAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) { |
| 260 | status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST; |
| 261 | } |
| 262 | } else { |
| 263 | // If this is a failed AAAA request, but the server only has a A record, |
| 264 | // then we should not fallback to Do53. Instead we also send a A request |
| 265 | // and return NS_ERROR_DEFINITIVE_UNKNOWN_HOST if that succeeds. |
| 266 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0))) && status != NS_ERROR_DEFINITIVE_UNKNOWN_HOST && |
| 267 | (mTrrAUsed == INIT || mTrrAAAAUsed == INIT)) { |
| 268 | if (newRRSet->TRRType() == TRRTYPE_A) { |
| 269 | LOG(("A lookup failed. Checking if AAAA record exists"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "A lookup failed. Checking if AAAA record exists"); } } while (0); |
| 270 | nsTArray<RefPtr<TRR>> requestsToSend; |
| 271 | PrepareQuery(TRRTYPE_AAAA, requestsToSend); |
| 272 | if (SendQueries(requestsToSend)) { |
| 273 | LOG(("Sent AAAA request"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "Sent AAAA request"); } } while (0); |
| 274 | return LOOKUP_OK; |
| 275 | } |
| 276 | } else if (newRRSet->TRRType() == TRRTYPE_AAAA) { |
| 277 | LOG(("AAAA lookup failed. Checking if A record exists"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "AAAA lookup failed. Checking if A record exists"); } } while (0); |
| 278 | nsTArray<RefPtr<TRR>> requestsToSend; |
| 279 | PrepareQuery(TRRTYPE_A, requestsToSend); |
| 280 | if (SendQueries(requestsToSend)) { |
| 281 | LOG(("Sent A request"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "Sent A request"); } } while (0); |
| 282 | return LOOKUP_OK; |
| 283 | } |
| 284 | } else { |
| 285 | MOZ_ASSERT(false, "Unexpected family")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected family" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 285); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Unexpected family" ")"); do { *((volatile int*)__null) = 285 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 286 | } |
| 287 | } |
| 288 | bool otherSucceeded = |
| 289 | mRecord->af == AF_INET610 ? mTrrAUsed == OK : mTrrAAAAUsed == OK; |
| 290 | LOG(("TRRQuery::CompleteLookup other request succeeded"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRRQuery::CompleteLookup other request succeeded"); } } while (0); |
| 291 | |
| 292 | if (mRecord->af == AF_INET2) { |
| 293 | // return only A record |
| 294 | newRRSet = mAddrInfoA; |
| 295 | status = mAResult; |
| 296 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0))) && |
| 297 | (otherSucceeded || mAAAAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) { |
| 298 | LOG(("status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"); } } while (0); |
| 299 | status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST; |
| 300 | } |
| 301 | |
| 302 | } else if (mRecord->af == AF_INET610) { |
| 303 | // return only AAAA record |
| 304 | newRRSet = mAddrInfoAAAA; |
| 305 | status = mAAAAResult; |
| 306 | |
| 307 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0))) && |
| 308 | (otherSucceeded || mAResult == NS_ERROR_DEFINITIVE_UNKNOWN_HOST)) { |
| 309 | LOG(("status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "status set to NS_ERROR_DEFINITIVE_UNKNOWN_HOST"); } } while (0); |
| 310 | status = NS_ERROR_DEFINITIVE_UNKNOWN_HOST; |
| 311 | } |
| 312 | |
| 313 | } else { |
| 314 | MOZ_ASSERT(false, "Unexpected AF")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected AF" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Unexpected AF" ")"); do { *((volatile int*)__null) = 314; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); |
| 315 | return LOOKUP_OK; |
| 316 | } |
| 317 | |
| 318 | // If this record failed, but there is a record for the other AF |
| 319 | // we prevent fallback to the native resolver. |
| 320 | } |
| 321 | |
| 322 | if (mTRRSuccess && mHostResolver->GetNCS() && |
| 323 | (mHostResolver->GetNCS()->GetNAT64() == |
| 324 | nsINetworkConnectivityService::OK) && |
| 325 | newRRSet) { |
| 326 | newRRSet = mHostResolver->GetNCS()->MapNAT64IPs(newRRSet); |
| 327 | } |
| 328 | |
| 329 | if (resolverType == DNSResolverType::TRR) { |
| 330 | if (mTrrAUsed == OK) { |
| 331 | AccumulateCategoricalKeyed( |
| 332 | TRRService::ProviderKey(), |
| 333 | Telemetry::LABELS_DNS_LOOKUP_DISPOSITION3::trrAOK); |
| 334 | } else if (mTrrAUsed == FAILED) { |
| 335 | AccumulateCategoricalKeyed( |
| 336 | TRRService::ProviderKey(), |
| 337 | Telemetry::LABELS_DNS_LOOKUP_DISPOSITION3::trrAFail); |
| 338 | } |
| 339 | |
| 340 | if (mTrrAAAAUsed == OK) { |
| 341 | AccumulateCategoricalKeyed( |
| 342 | TRRService::ProviderKey(), |
| 343 | Telemetry::LABELS_DNS_LOOKUP_DISPOSITION3::trrAAAAOK); |
| 344 | } else if (mTrrAAAAUsed == FAILED) { |
| 345 | AccumulateCategoricalKeyed( |
| 346 | TRRService::ProviderKey(), |
| 347 | Telemetry::LABELS_DNS_LOOKUP_DISPOSITION3::trrAAAAFail); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | mAddrInfoAAAA = nullptr; |
| 352 | mAddrInfoA = nullptr; |
| 353 | |
| 354 | MOZ_DIAGNOSTIC_ASSERT(!mCalledCompleteLookup,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mCalledCompleteLookup)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mCalledCompleteLookup))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mCalledCompleteLookup" " (" "must not call CompleteLookup more than once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 355); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mCalledCompleteLookup" ") (" "must not call CompleteLookup more than once" ")"); do { *((volatile int*)__null) = 355; __attribute__((nomerge)) :: abort(); } while (false); } } while (false) |
| 355 | "must not call CompleteLookup more than once")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mCalledCompleteLookup)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mCalledCompleteLookup))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mCalledCompleteLookup" " (" "must not call CompleteLookup more than once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 355); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mCalledCompleteLookup" ") (" "must not call CompleteLookup more than once" ")"); do { *((volatile int*)__null) = 355; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 356 | mCalledCompleteLookup = true; |
| 357 | return mHostResolver->CompleteLookup(rec, status, newRRSet, pb, aOriginsuffix, |
| 358 | aReason, aTRRRequest); |
| 359 | } |
| 360 | |
| 361 | AHostResolver::LookupStatus TRRQuery::CompleteLookupByType( |
| 362 | nsHostRecord* rec, nsresult status, |
| 363 | mozilla::net::TypeRecordResultType& aResult, |
| 364 | mozilla::net::TRRSkippedReason aReason, uint32_t aTtl, bool pb) { |
| 365 | if (rec != mRecord) { |
| 366 | LOG(("TRRQuery::CompleteLookup - Pushed record. Go to resolver"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHostResolverLog; if ((__builtin_expect(!!(mozilla::detail:: log_test(moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla ::detail::log_print(moz_real_module, mozilla::LogLevel::Debug , "TRRQuery::CompleteLookup - Pushed record. Go to resolver") ; } } while (0); |
| 367 | return mHostResolver->CompleteLookupByType(rec, status, aResult, aReason, |
| 368 | aTtl, pb); |
| 369 | } |
| 370 | |
| 371 | { |
| 372 | MutexAutoLock trrlock(mTrrLock); |
| 373 | mTrrByType = nullptr; |
| 374 | } |
| 375 | |
| 376 | // Unlike the address record, we store the duration regardless of the status. |
| 377 | mTrrDuration = TimeStamp::Now() - mTrrStart; |
| 378 | |
| 379 | MOZ_DIAGNOSTIC_ASSERT(!mCalledCompleteLookup,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mCalledCompleteLookup)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mCalledCompleteLookup))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mCalledCompleteLookup" " (" "must not call CompleteLookup more than once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 380); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mCalledCompleteLookup" ") (" "must not call CompleteLookup more than once" ")"); do { *((volatile int*)__null) = 380; __attribute__((nomerge)) :: abort(); } while (false); } } while (false) |
| 380 | "must not call CompleteLookup more than once")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mCalledCompleteLookup)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mCalledCompleteLookup))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mCalledCompleteLookup" " (" "must not call CompleteLookup more than once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/dns/TRRQuery.cpp" , 380); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mCalledCompleteLookup" ") (" "must not call CompleteLookup more than once" ")"); do { *((volatile int*)__null) = 380; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 381 | mCalledCompleteLookup = true; |
| 382 | return mHostResolver->CompleteLookupByType(rec, status, aResult, aReason, |
| 383 | aTtl, pb); |
| 384 | } |
| 385 | |
| 386 | } // namespace net |
| 387 | } // namespace mozilla |