History

fuzzers: add fuzzer for config parsers

Kacper Michajłow committed 2 years ago

Commit e1d1eb71 parent 467c1e82 files · +73 −0Browse files

Unified · Split

2 files
  1. fuzzers/fuzzer_load.c +65 −0
  2. fuzzers/meson.build +8 −0
fuzzers/fuzzer_load.c+65−0
@@ -0,0 +1,65 @@
1/*
2 * This file is part of mpv.
3 *
4 * mpv is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * mpv is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include <unistd.h>
23
24#include <libmpv/client.h>
25
26#include "common.h"
27
28int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
29{
30 if (size == 0)
31 return -1;
32
33 char filename[15 + 10 + 1];
34 sprintf(filename, "/tmp/libfuzzer.%d", getpid());
35
36 FILE *fp = fopen(filename, "wb");
37 if (!fp)
38 exit(1);
39
40 if (fwrite(data, size, 1, fp) != 1)
41 exit(1);
42
43 if (fclose(fp))
44 exit(1);
45
46 mpv_handle *ctx = mpv_create();
47 if (!ctx)
48 exit(1);
49
50 check_error(mpv_set_option_string(ctx, "vo", "null"));
51 check_error(mpv_set_option_string(ctx, "ao", "null"));
52 check_error(mpv_set_option_string(ctx, "ao-null-untimed", "yes"));
53 check_error(mpv_set_option_string(ctx, "untimed", "yes"));
54 check_error(mpv_set_option_string(ctx, "video-osd", "no"));
55 check_error(mpv_set_option_string(ctx, "msg-level", "all=trace"));
56
57 check_error(mpv_initialize(ctx));
58
59 const char *cmd[] = {"load-" MPV_LOAD, filename, NULL};
60 check_error(mpv_command(ctx, cmd));
61
62 mpv_terminate_destroy(ctx);
63
64 return 0;
65}
fuzzers/meson.build+8−0
@@ -24,3 +24,11 @@ foreach f : ['MPV_FORMAT_STRING', 'MPV_FORMAT_FLAG', 'MPV_FORMAT_INT64', 'MPV_FO · 23 unmodified lines
24 link_with: libmpv)24 link_with: libmpv)
25 endforeach25 endforeach
26endforeach26endforeach
27
28foreach cmd : ['config-file', 'input-conf']
29 executable('fuzzer_load_' + cmd.underscorify(),
30 'fuzzer_load.c',
31 c_args: ['-DMPV_LOAD="' + cmd + '"'],
32 include_directories: incdir,
33 link_with: libmpv)
34endforeach

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t