mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 20:06:18 +01:00
Reproducer for the null pw_name returned from getpwuid()
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
parent
17d6fc4e64
commit
d2107c17c8
45
glib/tests/getpwuid-preload.c
Normal file
45
glib/tests/getpwuid-preload.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* GLIB - Library of useful routines for C programming
|
||||
*
|
||||
* Copyright (C) 2020 Red Hat, Inc.
|
||||
*
|
||||
* Author: Jakub Jelen <jjelen@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct passwd my_pw;
|
||||
|
||||
/* This is used in gutils.c used to make sure utility functions
|
||||
* handling user information do not crash on bad data (for example
|
||||
* caused by getpwuid returning some NULL elements.
|
||||
*/
|
||||
struct passwd *
|
||||
getpwuid (uid_t uid)
|
||||
{
|
||||
static struct passwd *(*real_getpwuid) (uid_t);
|
||||
struct passwd *pw;
|
||||
|
||||
if (real_getpwuid == NULL)
|
||||
real_getpwuid = dlsym (RTLD_NEXT, "getpwuid");
|
||||
|
||||
pw = real_getpwuid (uid);
|
||||
my_pw = *pw;
|
||||
my_pw.pw_name = NULL;
|
||||
return &my_pw;
|
||||
}
|
43
glib/tests/gutils-user-database.c
Normal file
43
glib/tests/gutils-user-database.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Author: Jakub Jelen <jjelen@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* See the included COPYING file for more information.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* The function g_get_user_database_entry() is called from the
|
||||
* g_get_real_name(), g_get_user_name() and g_build_home_dir()
|
||||
* functions. These two calls are here just to invoke the code
|
||||
* paths. The real-test is the ld_preload used to inject the
|
||||
* NULL in place of pw->pw_name.
|
||||
*/
|
||||
static void
|
||||
test_get_user_database_entry (void)
|
||||
{
|
||||
const gchar *r = NULL;
|
||||
|
||||
r = g_get_user_name ();
|
||||
g_assert_nonnull (r);
|
||||
|
||||
r = g_get_real_name ();
|
||||
g_assert_nonnull (r);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_bug_base ("https://gitlab.gnome.org/GNOME/glib/issues");
|
||||
|
||||
g_test_add_func ("/gutils/get_user_database_entry", test_get_user_database_entry);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -148,6 +148,27 @@ else
|
||||
'include' : {},
|
||||
'unix' : {},
|
||||
}
|
||||
if have_rtld_next
|
||||
glib_tests += {
|
||||
'gutils-user-database' : {
|
||||
'depends' : [
|
||||
shared_library('getpwuid-preload',
|
||||
'getpwuid-preload.c',
|
||||
name_prefix : '',
|
||||
dependencies: libdl_dep,
|
||||
install_dir : installed_tests_execdir,
|
||||
install: installed_tests_enabled,
|
||||
),
|
||||
],
|
||||
'env' : {
|
||||
'LD_PRELOAD': '@0@/getpwuid-preload.so'.format(meson.current_build_dir()),
|
||||
},
|
||||
'installed_tests_env' : {
|
||||
'LD_PRELOAD': '@0@/getpwuid-preload.so'.format(installed_tests_execdir),
|
||||
},
|
||||
},
|
||||
}
|
||||
endif
|
||||
endif
|
||||
|
||||
if installed_tests_enabled
|
||||
|
Loading…
Reference in New Issue
Block a user