|
|
147e83 |
commit e2a9fca8101443076235a8dbcfceaa2d96bf4801
|
|
|
147e83 |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
147e83 |
Date: Sat Nov 11 11:33:32 2017 +0100
|
|
|
147e83 |
|
|
|
147e83 |
resolv: Add tst-ns_name_pton
|
|
|
147e83 |
|
|
|
147e83 |
diff --git a/resolv/Makefile b/resolv/Makefile
|
|
|
147e83 |
index b1fd2e2db8736f9b..0130a09db2d69451 100644
|
|
|
147e83 |
--- a/resolv/Makefile
|
|
|
147e83 |
+++ b/resolv/Makefile
|
|
|
147e83 |
@@ -49,6 +49,7 @@ tests += \
|
|
|
147e83 |
tst-bug18665-tcp \
|
|
|
147e83 |
tst-ns_name \
|
|
|
147e83 |
tst-ns_name_compress \
|
|
|
147e83 |
+ tst-ns_name_pton \
|
|
|
147e83 |
tst-res_hconf_reorder \
|
|
|
147e83 |
tst-res_hnok \
|
|
|
147e83 |
tst-res_use_inet6 \
|
|
|
147e83 |
@@ -183,6 +184,7 @@ $(objpfx)tst-resolv-canonname: \
|
|
|
147e83 |
$(objpfx)tst-ns_name: $(objpfx)libresolv.so
|
|
|
147e83 |
$(objpfx)tst-ns_name.out: tst-ns_name.data
|
|
|
147e83 |
$(objpfx)tst-ns_name_compress: $(objpfx)libresolv.so
|
|
|
147e83 |
+$(objpfx)tst-ns_name_pton: $(objpfx)libresolv.so
|
|
|
147e83 |
$(objpfx)tst-res_hnok: $(objpfx)libresolv.so
|
|
|
147e83 |
|
|
|
147e83 |
|
|
|
147e83 |
diff --git a/resolv/tst-ns_name_pton.c b/resolv/tst-ns_name_pton.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000000000000..879d97c9d3816210
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/resolv/tst-ns_name_pton.c
|
|
|
147e83 |
@@ -0,0 +1,203 @@
|
|
|
147e83 |
+/* Tests for ns_name_pton.
|
|
|
147e83 |
+ Copyright (C) 2017 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#include <arpa/nameser.h>
|
|
|
147e83 |
+#include <array_length.h>
|
|
|
147e83 |
+#include <stdbool.h>
|
|
|
147e83 |
+#include <stdio.h>
|
|
|
147e83 |
+#include <stdlib.h>
|
|
|
147e83 |
+#include <string.h>
|
|
|
147e83 |
+#include <support/check.h>
|
|
|
147e83 |
+#include <support/support.h>
|
|
|
147e83 |
+#include <support/test-driver.h>
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* Bits which indicate which functions are supposed to report
|
|
|
147e83 |
+ success. */
|
|
|
147e83 |
+enum
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ hnok = 1,
|
|
|
147e83 |
+ dnok = 2,
|
|
|
147e83 |
+ mailok = 4,
|
|
|
147e83 |
+ ownok = 8,
|
|
|
147e83 |
+ allnomailok = hnok | dnok | ownok,
|
|
|
147e83 |
+ allok = hnok | dnok | mailok | ownok
|
|
|
147e83 |
+ };
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 60 characters. */
|
|
|
147e83 |
+#define STRING60 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 63 characters (maximum label length). */
|
|
|
147e83 |
+#define STRING63 STRING60 "zzz"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 60 bytes (non-ASCII). */
|
|
|
147e83 |
+#define STRING60OCT \
|
|
|
147e83 |
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" \
|
|
|
147e83 |
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" \
|
|
|
147e83 |
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" \
|
|
|
147e83 |
+ "\377\377\377\377\377\377\377\377\377"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 63 bytes (non-ASCII). */
|
|
|
147e83 |
+#define STRING63OCT STRING60OCT "\377\377\377"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 60 bytes (non-ASCII, quoted decimal). */
|
|
|
147e83 |
+#define STRING60DEC \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255" \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255" \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255" \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255" \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255" \
|
|
|
147e83 |
+ "\\255\\255\\255\\255\\255\\255\\255\\255\\255\\255"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* A string of 63 bytes (non-ASCII, quoted decimal). */
|
|
|
147e83 |
+#define STRING63DEC STRING60DEC "\\255\\255\\255"
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* Combines a test name with the expected results. */
|
|
|
147e83 |
+struct test_case
|
|
|
147e83 |
+{
|
|
|
147e83 |
+ const char *dn;
|
|
|
147e83 |
+ const char *back; /* Expected test result converted using ns_name_ntop. */
|
|
|
147e83 |
+ bool fully_qualified; /* True if the domain name has a trailing dot. */
|
|
|
147e83 |
+};
|
|
|
147e83 |
+
|
|
|
147e83 |
+static const struct test_case tests[] =
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ { "", ".", false },
|
|
|
147e83 |
+ { ".", ".", true },
|
|
|
147e83 |
+ { "..", NULL, },
|
|
|
147e83 |
+ { "www", "www", false },
|
|
|
147e83 |
+ { "www.", "www", true },
|
|
|
147e83 |
+ { "www\\.", "www\\.", false },
|
|
|
147e83 |
+ { ".www", NULL, },
|
|
|
147e83 |
+ { ".www\\.", NULL, },
|
|
|
147e83 |
+ { "example.com", "example.com", false },
|
|
|
147e83 |
+ { "example.com.", "example.com", true },
|
|
|
147e83 |
+ { ".example.com", NULL, },
|
|
|
147e83 |
+ { ".example.com.", NULL, },
|
|
|
147e83 |
+ { "example\\.com", "example\\.com", false },
|
|
|
147e83 |
+ { "example\\.com.", "example\\.com", true },
|
|
|
147e83 |
+ { "example..", NULL, },
|
|
|
147e83 |
+ { "example..com", NULL, },
|
|
|
147e83 |
+ { "example..com", NULL, },
|
|
|
147e83 |
+ { "\\0", NULL, },
|
|
|
147e83 |
+ { "\\00", NULL, },
|
|
|
147e83 |
+ { "\\000", "\\000", false },
|
|
|
147e83 |
+ { "\\1", NULL, },
|
|
|
147e83 |
+ { "\\01", NULL, },
|
|
|
147e83 |
+ { "\\001", "\\001", false },
|
|
|
147e83 |
+ { "\\1x", NULL, },
|
|
|
147e83 |
+ { "\\01x", NULL, },
|
|
|
147e83 |
+ { "\\001x", "\\001x", false },
|
|
|
147e83 |
+ { "\\256", NULL, },
|
|
|
147e83 |
+ { "\\0641", "\\@1", false },
|
|
|
147e83 |
+ { "\\0011", "\\0011", false },
|
|
|
147e83 |
+ { STRING63, STRING63, false },
|
|
|
147e83 |
+ { STRING63 ".", STRING63, true },
|
|
|
147e83 |
+ { STRING63 "z", NULL, },
|
|
|
147e83 |
+ { STRING63 "\\.", NULL, },
|
|
|
147e83 |
+ { STRING60 "zz\\.", STRING60 "zz\\.", false },
|
|
|
147e83 |
+ { STRING60 "zz\\..", STRING60 "zz\\.", true },
|
|
|
147e83 |
+ { STRING63 "." STRING63 "." STRING63 "." STRING60 "z",
|
|
|
147e83 |
+ STRING63 "." STRING63 "." STRING63 "." STRING60 "z", false },
|
|
|
147e83 |
+ { STRING63 "." STRING63 "." STRING63 "." STRING60 "z.",
|
|
|
147e83 |
+ STRING63 "." STRING63 "." STRING63 "." STRING60 "z", true },
|
|
|
147e83 |
+ { STRING63 "." STRING63 "." STRING63 "." STRING60 "zz", NULL, },
|
|
|
147e83 |
+ { STRING63 "." STRING63 "." STRING63 "." STRING60 "zzz", NULL, },
|
|
|
147e83 |
+ { STRING63OCT "." STRING63OCT "." STRING63OCT "." STRING60OCT "\377",
|
|
|
147e83 |
+ STRING63DEC "." STRING63DEC "." STRING63DEC "." STRING60DEC "\\255",
|
|
|
147e83 |
+ false },
|
|
|
147e83 |
+ { STRING63OCT "." STRING63OCT "." STRING63OCT "." STRING60OCT "\377.",
|
|
|
147e83 |
+ STRING63DEC "." STRING63DEC "." STRING63DEC "." STRING60DEC "\\255",
|
|
|
147e83 |
+ true },
|
|
|
147e83 |
+ { STRING63OCT "." STRING63OCT "." STRING63OCT "." STRING60OCT
|
|
|
147e83 |
+ "\377\377", NULL, },
|
|
|
147e83 |
+ { STRING63OCT "." STRING63OCT "." STRING63OCT "." STRING60OCT
|
|
|
147e83 |
+ "\377\377\377", NULL, },
|
|
|
147e83 |
+ };
|
|
|
147e83 |
+
|
|
|
147e83 |
+static int
|
|
|
147e83 |
+do_test (void)
|
|
|
147e83 |
+{
|
|
|
147e83 |
+ unsigned char *wire = xmalloc (NS_MAXCDNAME);
|
|
|
147e83 |
+ char *text = xmalloc (NS_MAXDNAME);
|
|
|
147e83 |
+ for (const struct test_case *test = tests; test < array_end (tests); ++test)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ if (test_verbose)
|
|
|
147e83 |
+ printf ("info: testing domain name [[[%s]]]\n", test->dn);
|
|
|
147e83 |
+ int ret = ns_name_pton (test->dn, wire, NS_MAXCDNAME);
|
|
|
147e83 |
+ if (ret == -1)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ if (test->back != NULL)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: unexpected decoding failure for [[%s]]\n",
|
|
|
147e83 |
+ test->dn);
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+ /* Otherwise, we have an expected decoding failure. */
|
|
|
147e83 |
+ continue;
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (ret < -1 || ret > 1)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: invalid return value %d for [[%s]]\n",
|
|
|
147e83 |
+ ret, test->dn);
|
|
|
147e83 |
+ continue;
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ int ret2 = ns_name_ntop (wire, text, NS_MAXDNAME);
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (ret2 < 0)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: failure to convert back [[%s]]\n", test->dn);
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (test->back == NULL)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: unexpected success converting [[%s]]\n", test->dn);
|
|
|
147e83 |
+ if (ret2 >= 1)
|
|
|
147e83 |
+ printf ("error: result converts back to [[%s]]\n", test->dn);
|
|
|
147e83 |
+ continue;
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (strcmp (text, test->back) != 0)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: back-conversion of [[%s]] did not match\n",
|
|
|
147e83 |
+ test->dn);
|
|
|
147e83 |
+ printf ("error: expected: [[%s]]\n", test->back);
|
|
|
147e83 |
+ printf ("error: actual: [[%s]]\n", text);
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (ret != test->fully_qualified)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ support_record_failure ();
|
|
|
147e83 |
+ printf ("error: invalid fully-qualified status for [[%s]]\n",
|
|
|
147e83 |
+ test->dn);
|
|
|
147e83 |
+ printf ("error: expected: %d\n", (int) test->fully_qualified);
|
|
|
147e83 |
+ printf ("error: actual: %d\n", ret);
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+
|
|
|
147e83 |
+ free (text);
|
|
|
147e83 |
+ free (wire);
|
|
|
147e83 |
+ return 0;
|
|
|
147e83 |
+}
|
|
|
147e83 |
+
|
|
|
147e83 |
+#include <support/test-driver.c>
|