Fix lib/libc/nss/getgr_test with large numbers of groups

These tests create a linked list with one entry for every group on the
running system.  On a system with about 30,000 groups, the test took 69
seconds to run, and crashed Kyua with the below error:

kyua: E: string or blob too big (sqlite op: sqlite3_bind_blob) (sqlite db: /root/.kyua/store/results.usr_tests.20241231-203317-570235.db).

Fix the test by limiting it to operating on the first 1024 groups.
Apply the same change to getpw_test and getserv_test too, which are
vulnerable to the same problem.

MFC after:	2 weeks
Sponsored by:	ConnectWise
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D48275
This commit is contained in:
Alan Somers 2024-12-31 13:41:01 -07:00
parent 3b9da3dcd1
commit d11904b350
3 changed files with 12 additions and 0 deletions

View file

@ -293,6 +293,8 @@ group_fill_test_data(struct group_test_data *td,
int (*cb)(struct group *, void *))
{
struct group *grp;
const int limit = 1024;
int count = 0;
setgroupent(1);
while ((grp = getgrent()) != NULL) {
@ -303,6 +305,8 @@ group_fill_test_data(struct group_test_data *td,
} else {
return (-1);
}
if (++count >= limit)
break;
}
endgrent();

View file

@ -240,6 +240,8 @@ passwd_fill_test_data(struct passwd_test_data *td,
int (*cb)(struct passwd *, void *))
{
struct passwd *pwd;
const int limit = 1024;
int count = 0;
setpassent(1);
while ((pwd = getpwent()) != NULL) {
@ -250,6 +252,8 @@ passwd_fill_test_data(struct passwd_test_data *td,
} else {
return (-1);
}
if (++count >= limit)
break;
}
endpwent();

View file

@ -283,6 +283,8 @@ static int
servent_fill_test_data(struct servent_test_data *td)
{
struct servent *serv;
const int limit = 1024;
int count = 0;
setservent(1);
while ((serv = getservent()) != NULL) {
@ -290,6 +292,8 @@ servent_fill_test_data(struct servent_test_data *td)
TEST_DATA_APPEND(servent, td, serv);
else
return (-1);
if (++count >= limit)
break;
}
endservent();