1 /* Test program for bad DES salt detection in crypt.
2 Copyright (C) 2012-2015 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 <http://www.gnu.org/licenses/>. */
24 static const char *tests
[][2] =
27 { "single char", "/" },
28 { "first char bad", "!x" },
29 { "second char bad", "Z%" },
30 { "both chars bad", ":@" },
31 { "un$upported algorithm", "$2$" },
32 { "unsupported_algorithm", "_1" },
33 { "end of page", NULL
}
41 size_t n
= sizeof (tests
) / sizeof (*tests
);
42 size_t pagesize
= (size_t) sysconf (_SC_PAGESIZE
);
45 /* Check that crypt won't look at the second character if the first
47 page
= mmap (NULL
, pagesize
* 2, PROT_READ
| PROT_WRITE
,
48 MAP_PRIVATE
| MAP_ANON
, -1, 0);
49 if (page
== MAP_FAILED
)
56 if (mmap (page
+ pagesize
, pagesize
, 0,
57 MAP_PRIVATE
| MAP_ANON
| MAP_FIXED
,
58 -1, 0) != page
+ pagesize
)
60 page
[pagesize
- 1] = '*';
61 tests
[n
- 1][1] = &page
[pagesize
- 1];
64 for (size_t i
= 0; i
< n
; i
++)
66 if (crypt (tests
[i
][0], tests
[i
][1]))
69 printf ("%s: crypt returned non-NULL with salt \"%s\"\n",
70 tests
[i
][0], tests
[i
][1]);
73 if (crypt_r (tests
[i
][0], tests
[i
][1], &cd
))
76 printf ("%s: crypt_r returned non-NULL with salt \"%s\"\n",
77 tests
[i
][0], tests
[i
][1]);
85 #define TEST_FUNCTION do_test ()
86 #include "../test-skeleton.c"