2017-11-11 18:23:40 +08:00
|
|
|
/* Tests for res_hnok and related functions.
|
2020-01-01 08:14:33 +08:00
|
|
|
Copyright (C) 2017-2020 Free Software Foundation, Inc.
|
2017-11-11 18:23:40 +08:00
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2017-11-11 18:23:40 +08:00
|
|
|
|
|
|
|
#include <array_length.h>
|
|
|
|
#include <resolv.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <support/check.h>
|
|
|
|
#include <support/test-driver.h>
|
|
|
|
|
|
|
|
/* Bits which indicate which functions are supposed to report
|
|
|
|
success. */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
hnok = 1,
|
|
|
|
dnok = 2,
|
|
|
|
mailok = 4,
|
|
|
|
ownok = 8,
|
|
|
|
allnomailok = hnok | dnok | ownok,
|
|
|
|
allok = hnok | dnok | mailok | ownok
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A string of 60 characters. */
|
|
|
|
#define STRING60 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
|
|
|
|
|
|
|
|
/* A string of 63 characters (maximum label length). */
|
|
|
|
#define STRING63 STRING60 "zzz"
|
|
|
|
|
|
|
|
/* Combines a test name with the expected results. */
|
|
|
|
struct test_case
|
|
|
|
{
|
|
|
|
const char *dn;
|
|
|
|
unsigned int result; /* Combination of the *ok flags. */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct test_case tests[] =
|
|
|
|
{
|
|
|
|
{ "", allok },
|
|
|
|
{ ".", allok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ "..", 0 },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ "www", allnomailok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ "www.", allnomailok },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ "example", allnomailok },
|
|
|
|
{ "example.com", allok },
|
|
|
|
{ "www.example.com", allok },
|
|
|
|
{ "www.example.com.", allok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ "www-.example.com.", allok },
|
|
|
|
{ "www.-example.com.", allok },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ "*.example.com", dnok | mailok | ownok },
|
|
|
|
{ "-v", dnok },
|
|
|
|
{ "-v.example.com", mailok | dnok },
|
|
|
|
{ "**.example.com", dnok | mailok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ "www.example.com\\", 0 },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ STRING63, allnomailok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ STRING63 ".", allnomailok },
|
|
|
|
{ STRING63 "\\.", 0 },
|
|
|
|
{ STRING63 "z", 0 },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ STRING63 ".example.com", allok },
|
|
|
|
{ STRING63 "." STRING63 "." STRING63 "." STRING60 "z", allok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ STRING63 "." STRING63 "." STRING63 "." STRING60 "z.", allok },
|
|
|
|
{ STRING63 "." STRING63 "." STRING63 "." STRING60 "zz", 0 },
|
|
|
|
{ STRING63 "." STRING63 "." STRING63 "." STRING60 "zzz", 0 },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ "hostmaster@mail.example.com", dnok | mailok },
|
2017-11-11 18:51:08 +08:00
|
|
|
{ "hostmaster\\@mail.example.com", dnok | mailok },
|
2017-11-11 18:23:40 +08:00
|
|
|
{ "with whitespace", 0 },
|
|
|
|
{ "with\twhitespace", 0 },
|
|
|
|
{ "with\nwhitespace", 0 },
|
|
|
|
{ "with.whitespace ", 0 },
|
|
|
|
{ "with.whitespace\t", 0 },
|
|
|
|
{ "with.whitespace\n", 0 },
|
|
|
|
{ "with\\ whitespace", 0 },
|
|
|
|
{ "with\\\twhitespace", 0 },
|
|
|
|
{ "with\\\nwhitespace", 0 },
|
|
|
|
{ "with.whitespace\\ ", 0 },
|
|
|
|
{ "with.whitespace\\\t", 0 },
|
|
|
|
{ "with.whitespace\\\n", 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Run test case *TEST with FUNC (named FUNCNAME) and report an error
|
|
|
|
if the result does not match the result flag at BIT. */
|
|
|
|
static void
|
|
|
|
one_test (const struct test_case *test, const char *funcname,
|
|
|
|
int (*func) (const char *), unsigned int bit)
|
|
|
|
{
|
|
|
|
int expected = (test->result & bit) != 0;
|
|
|
|
int actual = func (test->dn);
|
|
|
|
if (actual != expected)
|
|
|
|
{
|
|
|
|
support_record_failure ();
|
|
|
|
printf ("error: %s (\"%s\"): expected=%d, actual=%d\n",
|
|
|
|
funcname, test->dn, expected, actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run 255 tests using all the bytes from 1 to 255, surround the byte
|
|
|
|
with the strings PREFIX and SUFFIX, and check that FUNC (named
|
|
|
|
FUNCNAME) accepts only those bytes listed in ACCEPTED. */
|
|
|
|
static void
|
|
|
|
one_char (const char *prefix, const char *accepted, const char *suffix,
|
|
|
|
const char *funcname, int (*func) (const char *))
|
|
|
|
{
|
|
|
|
for (int ch = 1; ch <= 255; ++ch)
|
|
|
|
{
|
|
|
|
char dn[1024];
|
|
|
|
snprintf (dn, sizeof (dn), "%s%c%s", prefix, ch, suffix);
|
|
|
|
int expected = strchr (accepted, ch) != NULL;
|
|
|
|
int actual = func (dn);
|
|
|
|
if (actual != expected)
|
|
|
|
{
|
|
|
|
support_record_failure ();
|
|
|
|
printf ("error: %s (\"%s\"): expected=%d, actual=%d\n",
|
|
|
|
funcname, dn, expected, actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 18:51:08 +08:00
|
|
|
#define LETTERSDIGITS \
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
|
|
|
|
#define PRINTABLE \
|
|
|
|
"!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~"
|
|
|
|
|
2017-11-11 18:23:40 +08:00
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
|
|
|
for (const struct test_case *test = tests; test < array_end (tests); ++test)
|
|
|
|
{
|
|
|
|
if (test_verbose)
|
|
|
|
printf ("info: testing domain name [[[%s]]] (0x%x)\n",
|
|
|
|
test->dn, test->result);
|
|
|
|
one_test (test, "res_hnok", res_hnok, hnok);
|
|
|
|
one_test (test, "res_dnok", res_dnok, dnok);
|
|
|
|
one_test (test, "res_mailok", res_mailok, mailok);
|
|
|
|
one_test (test, "res_ownok", res_ownok, ownok);
|
|
|
|
}
|
|
|
|
|
|
|
|
one_char
|
2017-11-11 18:51:08 +08:00
|
|
|
("", LETTERSDIGITS "._", "", "res_hnok", res_hnok);
|
2017-11-11 18:23:40 +08:00
|
|
|
one_char
|
|
|
|
("middle",
|
2017-11-11 18:51:08 +08:00
|
|
|
LETTERSDIGITS ".-_\\", /* "middle\\suffix" == "middlesuffix", so good. */
|
2017-11-11 18:23:40 +08:00
|
|
|
"suffix", "res_hnok", res_hnok);
|
|
|
|
one_char
|
|
|
|
("middle",
|
2017-11-11 18:51:08 +08:00
|
|
|
LETTERSDIGITS ".-_" PRINTABLE,
|
2017-11-11 18:23:40 +08:00
|
|
|
"suffix.example", "res_mailok", res_mailok);
|
|
|
|
one_char
|
|
|
|
("mailbox.middle",
|
2017-11-11 18:51:08 +08:00
|
|
|
LETTERSDIGITS ".-_\\",
|
2017-11-11 18:23:40 +08:00
|
|
|
"suffix.example", "res_mailok", res_mailok);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <support/test-driver.c>
|