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:
Philip Withnall
2022-01-31 14:55:50 +00:00
parent 44f4d55150
commit a6311f81ee
4 changed files with 64 additions and 7 deletions

View File

@@ -668,8 +668,8 @@ parse_args (gint *argc_p,
}
}
/* collapse argv */
e = 1;
for (i = 1; i < argc; i++)
e = 0;
for (i = 0; i < argc; i++)
if (argv[i])
{
argv[e++] = argv[i];