File: tst-resolv-trailing.c

package info (click to toggle)
glibc 2.28-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, buster-proposed-updates, experimental, sid
  • size: 272,168 kB
  • sloc: ansic: 1,008,602; asm: 259,607; makefile: 11,271; sh: 10,477; python: 6,910; cpp: 4,992; perl: 2,258; awk: 2,005; yacc: 290; pascal: 182; sed: 73
file content (136 lines) | stat: -rw-r--r-- 4,199 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Test name resolution behavior with trailing characters.
   Copyright (C) 2019 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <array_length.h>
#include <netdb.h>
#include <support/check.h>
#include <support/check_nss.h>
#include <support/resolv_test.h>
#include <support/support.h>

static void
response (const struct resolv_response_context *ctx,
          struct resolv_response_builder *b,
          const char *qname, uint16_t qclass, uint16_t qtype)
{
  /* The tests are not supposed send any DNS queries.  */
  FAIL_EXIT1 ("unexpected DNS query for %s/%d/%d", qname, qclass, qtype);
}

static int
do_test (void)
{
  struct resolv_test *aux = resolv_test_start
    ((struct resolv_redirect_config)
     {
       .response_callback = response,
     });

  static const char *const queries[] =
    {
     "192.0.2.1 ",
     "192.0.2.2\t",
     "192.0.2.3\n",
     "192.0.2.4 X",
     "192.0.2.5\tY",
     "192.0.2.6\nZ",
     "192.0.2. ",
     "192.0.2.\t",
     "192.0.2.\n",
     "192.0.2. X",
     "192.0.2.\tY",
     "192.0.2.\nZ",
     "2001:db8::1 ",
     "2001:db8::2\t",
     "2001:db8::3\n",
     "2001:db8::4 X",
     "2001:db8::5\tY",
     "2001:db8::6\nZ",
    };
  for (size_t query_idx = 0; query_idx < array_length (queries); ++query_idx)
    {
      const char *query = queries[query_idx];
      struct hostent storage;
      char buf[4096];
      struct hostent *e;

      h_errno = 0;
      TEST_VERIFY (gethostbyname (query) == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      h_errno = 0;
      e = NULL;
      TEST_COMPARE (gethostbyname_r (query, &storage, buf, sizeof (buf),
                                     &e, &h_errno), 0);
      TEST_VERIFY (e == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      h_errno = 0;
      TEST_VERIFY (gethostbyname2 (query, AF_INET) == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      h_errno = 0;
      e = NULL;
      TEST_COMPARE (gethostbyname2_r (query, AF_INET,
                                      &storage, buf, sizeof (buf),
                                     &e, &h_errno), 0);
      TEST_VERIFY (e == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      h_errno = 0;
      TEST_VERIFY (gethostbyname2 (query, AF_INET6) == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      h_errno = 0;
      e = NULL;
      TEST_COMPARE (gethostbyname2_r (query, AF_INET6,
                                      &storage, buf, sizeof (buf),
                                     &e, &h_errno), 0);
      TEST_VERIFY (e == NULL);
      TEST_COMPARE (h_errno, HOST_NOT_FOUND);

      static const int gai_flags[] =
        {
         0,
         AI_ADDRCONFIG,
         AI_NUMERICHOST,
         AI_IDN,
         AI_IDN | AI_NUMERICHOST,
         AI_V4MAPPED,
         AI_V4MAPPED | AI_NUMERICHOST,
        };
      for (size_t gai_flags_idx; gai_flags_idx < array_length (gai_flags);
             ++gai_flags_idx)
        {
          struct addrinfo hints = { .ai_flags = gai_flags[gai_flags_idx], };
          struct addrinfo *ai;
          hints.ai_family = AF_INET;
          TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
          hints.ai_family = AF_INET6;
          TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
          hints.ai_family = AF_UNSPEC;
          TEST_COMPARE (getaddrinfo (query, "80", &hints, &ai), EAI_NONAME);
        }
    };

  resolv_test_end (aux);

  return 0;
}

#include <support/test-driver.c>