Merge branch 'fuzz-string-replace-oom' into 'main'

fuzzing: Add input length limits on g_string_replace() test

See merge request GNOME/glib!4334
This commit is contained in:
Michael Catanzaro 2024-10-07 21:54:19 +00:00
commit bb0d3d2c1c

View File

@ -40,6 +40,20 @@ LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
find = (n_args > 1) ? args[1] : "";
replace = (n_args > 2) ? args[2] : "";
/* Limit the input size. With a short @find, and a long @init and @replace
* its quite possible to hit OOM. Were not interested in testing that its
* up to the caller of g_string_replace() to handle that. 1KB on each of the
* inputs should be plenty to find any string parsing or pointer arithmetic
* bugs in g_string_replace(). */
if (strlen (init) > 1000 ||
strlen (find) > 1000 ||
strlen (replace) > 1000)
{
g_strfreev (args);
g_free (nul_terminated_data);
return 0;
}
/* Test g_string_replace() and see if it crashes. */
string = g_string_new (init);
g_string_replace (string, find, replace, 0);