1 | /* Test large input for sgetsgent (bug 30151). |
2 | Copyright (C) 2023 Free Software Foundation, Inc. |
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 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <gshadow.h> |
20 | #include <stddef.h> |
21 | #include <support/check.h> |
22 | #include <support/support.h> |
23 | #include <support/xmemstream.h> |
24 | #include <stdlib.h> |
25 | |
26 | static int |
27 | do_test (void) |
28 | { |
29 | /* Create a shadow group with 1000 members. */ |
30 | struct xmemstream mem; |
31 | xopen_memstream (stream: &mem); |
32 | const char *passwd = "k+zD0nucwfxAo3sw1NXUj6K5vt5M16+X0TVGdE1uFvq5R8V7efJ" ; |
33 | fprintf (mem.out, "group-name:%s::m0" , passwd); |
34 | for (int i = 1; i < 1000; ++i) |
35 | fprintf (mem.out, ",m%d" , i); |
36 | xfclose_memstream (stream: &mem); |
37 | |
38 | /* Call sgetsgent. */ |
39 | char *input = mem.buffer; |
40 | struct sgrp *e = sgetsgent (string: input); |
41 | TEST_VERIFY_EXIT (e != NULL); |
42 | TEST_COMPARE_STRING (e->sg_namp, "group-name" ); |
43 | TEST_COMPARE_STRING (e->sg_passwd, passwd); |
44 | /* No administrators. */ |
45 | TEST_COMPARE_STRING (e->sg_adm[0], NULL); |
46 | /* Check the members list. */ |
47 | for (int i = 0; i < 1000; ++i) |
48 | { |
49 | char *member = xasprintf (format: "m%d" , i); |
50 | TEST_COMPARE_STRING (e->sg_mem[i], member); |
51 | free (ptr: member); |
52 | } |
53 | TEST_COMPARE_STRING (e->sg_mem[1000], NULL); |
54 | |
55 | /* Check that putsgent brings back the input string. */ |
56 | xopen_memstream (stream: &mem); |
57 | TEST_COMPARE (putsgent (e, mem.out), 0); |
58 | xfclose_memstream (stream: &mem); |
59 | /* Compare without the trailing '\n' that putsgent added. */ |
60 | TEST_COMPARE (mem.buffer[mem.length - 1], '\n'); |
61 | mem.buffer[mem.length - 1] = '\0'; |
62 | TEST_COMPARE_STRING (mem.buffer, input); |
63 | |
64 | free (ptr: mem.buffer); |
65 | free (ptr: input); |
66 | return 0; |
67 | } |
68 | |
69 | #include <support/test-driver.c> |
70 | |