1 /* Test ns_name_compress corner cases.
2 Copyright (C) 2017-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
22 #include <support/check.h>
23 #include <support/support.h>
25 /* Check that we can process names which fit into the destination
26 buffer exactly. See bug 21359. */
28 test_exact_fit (const char *name
, size_t length
)
30 unsigned char *buf
= xmalloc (length
+ 1);
31 memset (buf
, '$', length
+ 1);
32 enum { ptr_count
= 5 };
33 const unsigned char *dnptrs
[ptr_count
] = { buf
, };
34 int ret
= ns_name_compress (name
, buf
, length
,
35 dnptrs
, dnptrs
+ ptr_count
);
38 support_record_failure ();
39 printf ("error: ns_name_compress for %s/%zu failed\n", name
, length
);
42 if ((size_t) ret
!= length
)
44 support_record_failure ();
45 printf ("error: ns_name_compress for %s/%zu result mismatch: %d\n",
48 if (buf
[length
] != '$')
50 support_record_failure ();
51 printf ("error: ns_name_compress for %s/%zu padding write\n",
60 test_exact_fit ("abc", 5);
61 test_exact_fit ("abc.", 5);
64 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
65 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
66 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
67 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.";
68 TEST_VERIFY (strlen (long_name
) == NS_MAXCDNAME
- 1);
69 test_exact_fit (long_name
, NS_MAXCDNAME
);
70 long_name
[sizeof (long_name
) - 1] = '\0';
71 test_exact_fit (long_name
, NS_MAXCDNAME
);
76 #include <support/test-driver.c>