mirror of https://github.com/mpv-player/mpv
fuzzers/fuzzer_json: add simple fuzzing for our json code
This commit is contained in:
parent
207aa647a5
commit
d78c35d360
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* This file is part of mpv.
|
||||||
|
*
|
||||||
|
* mpv 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.
|
||||||
|
*
|
||||||
|
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include "misc/json.h"
|
||||||
|
#include "mpv_talloc.h"
|
||||||
|
|
||||||
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
|
{
|
||||||
|
void *tmp = talloc_new(NULL);
|
||||||
|
char *s = talloc_array_ptrtype(tmp, s, size + 1);
|
||||||
|
memcpy(s, data, size);
|
||||||
|
s[size] = '\0';
|
||||||
|
|
||||||
|
json_skip_whitespace(&s);
|
||||||
|
|
||||||
|
struct mpv_node res;
|
||||||
|
if (!json_parse(tmp, &res, &s, MAX_JSON_DEPTH)) {
|
||||||
|
char *d = talloc_strdup(tmp, "");
|
||||||
|
json_write(&d, &res);
|
||||||
|
|
||||||
|
d[0] = '\0';
|
||||||
|
json_write_pretty(&d, &res);
|
||||||
|
}
|
||||||
|
|
||||||
|
talloc_free(tmp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -76,4 +76,9 @@ fuzzers += executable('fuzzer_options_parser', 'fuzzer_options_parser.c',
|
||||||
objects: libmpv.extract_all_objects(recursive: true),
|
objects: libmpv.extract_all_objects(recursive: true),
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
|
fuzzers += executable('fuzzer_json', 'fuzzer_json.c',
|
||||||
|
link_language: 'cpp', include_directories: incdir,
|
||||||
|
objects: libmpv.extract_all_objects(recursive: true),
|
||||||
|
dependencies: dependencies)
|
||||||
|
|
||||||
alias_target('fuzzers', fuzzers)
|
alias_target('fuzzers', fuzzers)
|
||||||
|
|
Loading…
Reference in New Issue