From c0a25aa92b612786f4e45292c4aee1d7d47123f8 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sat, 11 Nov 2017 11:51:08 +0100 Subject: resolv: More precise checks in res_hnok, res_dnok [BZ #22409] [BZ #22412] res_hnok rejected some host names used on the Internet, such as www-.example.com. res_hnok and res_dnok failed to perform basic syntax checking on DNS domain names. Also fix res_mailok, res_ownok. --- resolv/tst-res_hnok.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'resolv/tst-res_hnok.c') diff --git a/resolv/tst-res_hnok.c b/resolv/tst-res_hnok.c index 9c92303821..314477a2ce 100644 --- a/resolv/tst-res_hnok.c +++ b/resolv/tst-res_hnok.c @@ -51,19 +51,31 @@ static const struct test_case tests[] = { { "", allok }, { ".", allok }, + { "..", 0 }, { "www", allnomailok }, + { "www.", allnomailok }, { "example", allnomailok }, { "example.com", allok }, { "www.example.com", allok }, { "www.example.com.", allok }, + { "www-.example.com.", allok }, + { "www.-example.com.", allok }, { "*.example.com", dnok | mailok | ownok }, { "-v", dnok }, { "-v.example.com", mailok | dnok }, { "**.example.com", dnok | mailok }, + { "www.example.com\\", 0 }, { STRING63, allnomailok }, + { STRING63 ".", allnomailok }, + { STRING63 "\\.", 0 }, + { STRING63 "z", 0 }, { STRING63 ".example.com", allok }, { STRING63 "." STRING63 "." STRING63 "." STRING60 "z", allok }, + { STRING63 "." STRING63 "." STRING63 "." STRING60 "z.", allok }, + { STRING63 "." STRING63 "." STRING63 "." STRING60 "zz", 0 }, + { STRING63 "." STRING63 "." STRING63 "." STRING60 "zzz", 0 }, { "hostmaster@mail.example.com", dnok | mailok }, + { "hostmaster\\@mail.example.com", dnok | mailok }, { "with whitespace", 0 }, { "with\twhitespace", 0 }, { "with\nwhitespace", 0 }, @@ -116,6 +128,12 @@ one_char (const char *prefix, const char *accepted, const char *suffix, } } +#define LETTERSDIGITS \ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + +#define PRINTABLE \ + "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~" + static int do_test (void) { @@ -131,20 +149,18 @@ do_test (void) } one_char - ("", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.", - "", "res_hnok", res_hnok); + ("", LETTERSDIGITS "._", "", "res_hnok", res_hnok); one_char ("middle", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_", + LETTERSDIGITS ".-_\\", /* "middle\\suffix" == "middlesuffix", so good. */ "suffix", "res_hnok", res_hnok); one_char ("middle", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_" - "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~", + LETTERSDIGITS ".-_" PRINTABLE, "suffix.example", "res_mailok", res_mailok); one_char ("mailbox.middle", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_", + LETTERSDIGITS ".-_\\", "suffix.example", "res_mailok", res_mailok); return 0; -- cgit v1.2.3