From patchwork Sat Nov 11 10:38:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 837016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-86975-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="qC0oIckn"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yYtgR0ydGz9s74 for ; Sat, 11 Nov 2017 21:39:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= HKcfbUUQrisEich9WaWmJEaqQbNjpr7P343H/gg1cnheNHlxhsl4JDRYzAW/qVEX bK9dbPAi7G1l5fFnu2SBkm/PfCNT3a7O0kSmbSz+/yL3x9t7qary7pgFagt+oj54 QO1eVzdyBUfBFmGMceZSHYS/aO9sCZRrMFmCij9UNOY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=QTxdEM t9IXf58QbmP8YbUXAKfN0=; b=qC0oIcknMXTM8YSSFdjY78OIr9LHEvkTkqLg9+ QtelP4M45k1DTqhiKVYs7t2Z24Vmm6TmWe7OZphieNMUnkuLbTlADZ3y9W57oSSN 8gzMAxSqkFFS7tIBm6/cFVPA95Kr6+JRYt86Rcz7zBGRH4dmnPrOAgaVnZ8Ch6sz sob8A= Received: (qmail 104155 invoked by alias); 11 Nov 2017 10:39:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 101350 invoked by uid 89); 11 Nov 2017 10:39:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Date: Sat, 11 Nov 2017 11:38:58 +0100 To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED] resolv: Add tst-res_hnok User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20171111103858.77D34439942E9@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-11-11 Florian Weimer * resolv/tst-res_hnok.c: New file. * resolv/Makefile (tests): Add tst-res_hnok. (tst-res_hnok): Link against libresolv. diff --git a/resolv/Makefile b/resolv/Makefile index 0f1fcc1014..0b8dbf2552 100644 --- a/resolv/Makefile +++ b/resolv/Makefile @@ -47,6 +47,7 @@ tests += \ tst-ns_name \ tst-ns_name_compress \ tst-res_hconf_reorder \ + tst-res_hnok \ tst-res_use_inet6 \ tst-resolv-basic \ tst-resolv-edns \ @@ -172,6 +173,7 @@ $(objpfx)tst-resolv-canonname: \ $(objpfx)tst-ns_name: $(objpfx)libresolv.so $(objpfx)tst-ns_name.out: tst-ns_name.data $(objpfx)tst-ns_name_compress: $(objpfx)libresolv.so +$(objpfx)tst-res_hnok: $(objpfx)libresolv.so # This test case uses the deprecated RES_USE_INET6 resolver option. diff --git a/resolv/tst-res_hnok.c b/resolv/tst-res_hnok.c new file mode 100644 index 0000000000..9c92303821 --- /dev/null +++ b/resolv/tst-res_hnok.c @@ -0,0 +1,153 @@ +/* Tests for res_hnok and related functions. + Copyright (C) 2017 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 + . */ + +#include +#include +#include +#include +#include + +/* 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 }, + { "www", allnomailok }, + { "example", allnomailok }, + { "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 }, + { STRING63, allnomailok }, + { STRING63 ".example.com", allok }, + { STRING63 "." STRING63 "." STRING63 "." STRING60 "z", allok }, + { "hostmaster@mail.example.com", dnok | mailok }, + { "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); + } + } +} + +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 + ("", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.", + "", "res_hnok", res_hnok); + one_char + ("middle", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_", + "suffix", "res_hnok", res_hnok); + one_char + ("middle", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_" + "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~", + "suffix.example", "res_mailok", res_mailok); + one_char + ("mailbox.middle", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_", + "suffix.example", "res_mailok", res_mailok); + + return 0; +} + +#include