mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-22 00:48:53 +02:00
gtestutils: Handle empty argv array passed to g_test_init()
This can happen if a caller (ab)uses `execve()` to execute a gtest process with an empty `argv` array. `g_test_init()` has to gracefully handle such a situation. Fix a few problem areas in the code, and add a simple test which checks that `g_test_init()` doesn’t crash when called with an empty `argv`. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
@@ -102,6 +102,24 @@ main (int argc,
|
||||
argc -= 1;
|
||||
argv[argc] = NULL;
|
||||
|
||||
if (g_strcmp0 (argv1, "init-null-argv0") == 0)
|
||||
{
|
||||
int test_argc = 0;
|
||||
char *test_argva[1] = { NULL };
|
||||
char **test_argv = test_argva;
|
||||
|
||||
/* Test that `g_test_init()` can handle being called with an empty argv
|
||||
* and argc == 0. While this isn’t recommended, it is possible for another
|
||||
* process to use execve() to call a gtest process this way, so we’d
|
||||
* better handle it gracefully.
|
||||
*
|
||||
* This test can’t be run after `g_test_init()` has been called normally,
|
||||
* as it isn’t allowed to be called more than once in a process. */
|
||||
g_test_init (&test_argc, &test_argv, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_set_nonfatal_assertions ();
|
||||
|
||||
|
Reference in New Issue
Block a user