riscv: align stack before calling _dl_init [BZ #28703]
[glibc.git] / resolv / tst-resolv-trailing.c
blobc6e2dde97831abfed101fa3159664b9ebdad3f48
1 /* Test name resolution behavior with trailing characters.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <array_length.h>
20 #include <netdb.h>
21 #include <support/check.h>
22 #include <support/check_nss.h>
23 #include <support/resolv_test.h>
24 #include <support/support.h>
26 static void
27 response (const struct resolv_response_context *ctx,
28 struct resolv_response_builder *b,
29 const char *qname, uint16_t qclass, uint16_t qtype)
31 /* The tests are not supposed send any DNS queries. */
32 FAIL_EXIT1 ("unexpected DNS query for %s/%d/%d", qname, qclass, qtype);
35 static int
36 do_test (void)
38 struct resolv_test *aux = resolv_test_start
39 ((struct resolv_redirect_config)
41 .response_callback = response,
42 });
44 static const char *const queries[] =
46 "192.0.2.1 ",
47 "192.0.2.2\t",
48 "192.0.2.3\n",
49 "192.0.2.4 X",
50 "192.0.2.5\tY",
51 "192.0.2.6\nZ",
52 "192.0.2. ",
53 "192.0.2.\t",
54 "192.0.2.\n",
55 "192.0.2. X",
56 "192.0.2.\tY",
57 "192.0.2.\nZ",
58 "2001:db8::1 ",
59 "2001:db8::2\t",
60 "2001:db8::3\n",
61 "2001:db8::4 X",
62 "2001:db8::5\tY",
63 "2001:db8::6\nZ",
65 for (size_t query_idx = 0; query_idx < array_length (queries); ++query_idx)
67 const char *query = queries[query_idx];
68 struct hostent storage;
69 char buf[4096];
70 struct hostent *e;
72 h_errno = 0;
73 TEST_VERIFY (gethostbyname (query) == NULL);
74 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
76 h_errno = 0;
77 e = NULL;
78 TEST_COMPARE (gethostbyname_r (query, &storage, buf, sizeof (buf),
79 &e, &h_errno), 0);
80 TEST_VERIFY (e == NULL);
81 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
83 h_errno = 0;
84 TEST_VERIFY (gethostbyname2 (query, AF_INET) == NULL);
85 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
87 h_errno = 0;
88 e = NULL;
89 TEST_COMPARE (gethostbyname2_r (query, AF_INET,
90 &storage, buf, sizeof (buf),
91 &e, &h_errno), 0);
92 TEST_VERIFY (e == NULL);
93 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
95 h_errno = 0;
96 TEST_VERIFY (gethostbyname2 (query, AF_INET6) == NULL);
97 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
99 h_errno = 0;
100 e = NULL;
101 TEST_COMPARE (gethostbyname2_r (query, AF_INET6,
102 &storage, buf, sizeof (buf),
103 &e, &h_errno), 0);
104 TEST_VERIFY (e == NULL);
105 TEST_COMPARE (h_errno, HOST_NOT_FOUND);
107 static const int gai_flags[] =
110 AI_ADDRCONFIG,
111 AI_NUMERICHOST,
112 AI_IDN,
113 AI_IDN | AI_NUMERICHOST,
114 AI_V4MAPPED,
115 AI_V4MAPPED | AI_NUMERICHOST,
117 for (size_t gai_flags_idx; gai_flags_idx < array_length (gai_flags);
118 ++gai_flags_idx)
120 struct addrinfo hints = { .ai_flags = gai_flags[gai_flags_idx], };
121 struct addrinfo *ai;
122 hints.ai_family = AF_INET;
123 TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
124 hints.ai_family = AF_INET6;
125 TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
126 hints.ai_family = AF_UNSPEC;
127 TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
131 resolv_test_end (aux);
133 return 0;
136 #include <support/test-driver.c>