Fixed crash when HTTPS response is not correct

This commit is contained in:
PeratX 2018-07-08 14:30:23 +08:00
parent 1feb5a0074
commit e178184df9
3 changed files with 64 additions and 58 deletions

View File

@ -43,7 +43,7 @@ Supported DNS Query Methods:
* UDP
* TCP
* DNS over TLS ([RFC7858](https://tools.ietf.org/html/rfc7858))
* DNS over HTTPS ([IETF darft](https://tools.ietf.org/html/draft-ietf-doh-dns-over-https-11))
* DNS over HTTPS ([IETF darft](https://tools.ietf.org/html/draft-ietf-doh-dns-over-https-12))
* DNS over HTTPS ([Google JSON](https://developers.google.com/speed/public-dns/docs/dns-over-https))
<br>

View File

@ -65,11 +65,14 @@ public class HttpsIetfProvider extends HttpsProvider {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
try {
result = new DnsMessage(response.body().bytes()).asBuilder()
.setId(id).build().toArray();
completed = true;
} catch (Exception ignored) {//throw IllegalArgumentException when response is not correct
}
}
}
});

View File

@ -72,8 +72,9 @@ public class HttpsJsonProvider extends HttpsProvider {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
try {
JsonObject jsonObject = new JsonParser().parse(response.body().string()).getAsJsonObject();
DnsMessage.Builder msg = message.asBuilder()
.setRecursionDesired(jsonObject.get("RD").getAsBoolean())
@ -130,6 +131,8 @@ public class HttpsJsonProvider extends HttpsProvider {
}
result = msg.setQrFlag(true).build().toArray();
completed = true;
} catch (Exception ignored) {//throw com.google.gson.JsonSyntaxException when response is not correct
}
}
}
});