]>
Commit | Line | Data |
---|---|---|
676599b3 | 1 | /* Test for invalid field handling in file-style NSS databases. [BZ #18724] |
04277e02 | 2 | Copyright (C) 2015-2019 Free Software Foundation, Inc. |
676599b3 FW |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | /* This test needs to be statically linked because it access hidden | |
20 | functions. */ | |
21 | ||
22 | #include <nss.h> | |
23 | #include <stdbool.h> | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <string.h> | |
27 | ||
a3fe6a20 DD |
28 | #include <support/support.h> |
29 | ||
676599b3 FW |
30 | static bool errors; |
31 | ||
32 | static void | |
33 | check (const char *what, bool expr) | |
34 | { | |
35 | if (!expr) | |
36 | { | |
37 | printf ("FAIL: %s\n", what); | |
38 | errors = true; | |
39 | } | |
40 | } | |
41 | ||
42 | #define CHECK(expr) check (#expr, (expr)) | |
43 | ||
44 | static void | |
45 | check_rewrite (const char *input, const char *expected) | |
46 | { | |
47 | char *to_free; | |
48 | const char *result = __nss_rewrite_field (input, &to_free); | |
49 | CHECK (result != NULL); | |
50 | if (result != NULL && strcmp (result, expected) != 0) | |
51 | { | |
52 | printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n", | |
53 | input, result, expected); | |
54 | errors = true; | |
55 | } | |
56 | free (to_free); | |
57 | } | |
58 | ||
59 | static int | |
60 | do_test (void) | |
61 | { | |
62 | CHECK (__nss_valid_field (NULL)); | |
63 | CHECK (__nss_valid_field ("")); | |
64 | CHECK (__nss_valid_field ("+")); | |
65 | CHECK (__nss_valid_field ("-")); | |
66 | CHECK (__nss_valid_field (" ")); | |
67 | CHECK (__nss_valid_field ("abcdef")); | |
68 | CHECK (__nss_valid_field ("abc def")); | |
69 | CHECK (__nss_valid_field ("abc\tdef")); | |
70 | CHECK (!__nss_valid_field ("abcdef:")); | |
71 | CHECK (!__nss_valid_field ("abcde:f")); | |
72 | CHECK (!__nss_valid_field (":abcdef")); | |
73 | CHECK (!__nss_valid_field ("abcdef\n")); | |
74 | CHECK (!__nss_valid_field ("\nabcdef")); | |
75 | CHECK (!__nss_valid_field (":")); | |
76 | CHECK (!__nss_valid_field ("\n")); | |
77 | ||
78 | CHECK (__nss_valid_list_field (NULL)); | |
79 | CHECK (__nss_valid_list_field ((char *[]) {(char *) "good", NULL})); | |
80 | CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g,ood", NULL})); | |
81 | CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g\nood", NULL})); | |
82 | CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g:ood", NULL})); | |
83 | ||
84 | check_rewrite (NULL, ""); | |
85 | check_rewrite ("", ""); | |
86 | check_rewrite ("abc", "abc"); | |
87 | check_rewrite ("abc\n", "abc "); | |
88 | check_rewrite ("abc:", "abc "); | |
89 | check_rewrite ("\nabc", " abc"); | |
90 | check_rewrite (":abc", " abc"); | |
91 | check_rewrite (":", " "); | |
92 | check_rewrite ("\n", " "); | |
93 | check_rewrite ("a:b:c", "a b c"); | |
94 | check_rewrite ("a\nb\nc", "a b c"); | |
95 | check_rewrite ("a\nb:c", "a b c"); | |
96 | check_rewrite ("aa\nbb\ncc", "aa bb cc"); | |
97 | check_rewrite ("aa\nbb:cc", "aa bb cc"); | |
98 | ||
99 | return errors; | |
100 | } | |
101 | ||
a3fe6a20 | 102 | #include <support/test-driver.c> |