[glib: 6/13] gthreadedresolver: Don’t warn on unrecognised record types
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 6/13] gthreadedresolver: Don’t warn on unrecognised record types
- Date: Tue, 22 Mar 2022 15:18:52 +0000 (UTC)
commit 81193c5aac04059455dc24aa573b06e1e773d700
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Mar 18 15:52:18 2022 +0000
gthreadedresolver: Don’t warn on unrecognised record types
Otherwise the code isn’t forwards-compatible, and may be DOSed by
servers returning unknown records, if `G_DEBUG=fatal-warnings` is
enabled for some reason.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
gio/gthreadedresolver.c | 2 +-
gio/tests/resolver-parsing.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
---
diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c
index 59f229a16c..5682102038 100644
--- a/gio/gthreadedresolver.c
+++ b/gio/gthreadedresolver.c
@@ -780,7 +780,7 @@ g_resolver_records_from_res_query (const gchar *rrname,
record = parse_res_txt (answer, p + rdlength, &p);
break;
default:
- g_warn_if_reached ();
+ g_debug ("Unrecognised DNS record type %u", rrtype);
record = NULL;
break;
}
diff --git a/gio/tests/resolver-parsing.c b/gio/tests/resolver-parsing.c
index bf1ba1b736..909917be86 100644
--- a/gio/tests/resolver-parsing.c
+++ b/gio/tests/resolver-parsing.c
@@ -146,6 +146,42 @@ test_invalid_header (void)
}
}
+static void
+test_unknown_record_type (void)
+{
+#ifndef HAVE_DN_COMP
+ g_test_skip ("The dn_comp() function was not available.");
+ return;
+#else
+ GByteArray *answer = NULL;
+ GList *records = NULL;
+ GError *local_error = NULL;
+ const guint type_id = 20; /* ISDN, not supported anywhere */
+
+ /* An answer with an unsupported type chosen from
+ * https://en.wikipedia.org/wiki/List_of_DNS_record_types#[1]_Obsolete_record_types */
+ answer = dns_header ();
+ dns_builder_add_domain (answer, "example.org");
+ dns_builder_add_uint16 (answer, type_id);
+ dns_builder_add_uint16 (answer, 1); /* qclass=C_IN */
+ dns_builder_add_uint32 (answer, 0); /* ttl (ignored) */
+ dns_builder_add_uint16 (answer, 0); /* rdlength */
+
+ records = g_resolver_records_from_res_query ("example.org",
+ type_id,
+ answer->data,
+ answer->len,
+ 0,
+ &local_error);
+
+ g_assert_error (local_error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND);
+ g_assert_null (records);
+ g_clear_error (&local_error);
+
+ g_byte_array_free (answer, TRUE);
+#endif
+}
+
int
main (int argc,
char *argv[])
@@ -153,6 +189,7 @@ main (int argc,
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
g_test_add_func ("/gresolver/invalid-header", test_invalid_header);
+ g_test_add_func ("/gresolver/unknown-record-type", test_unknown_record_type);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]