History

fuzzer_loadfile_direct: exclude paths also for file://

Loading external files makes little sense. Might disable this completely later, but let see how it works, The idea is the same as for direct load. Exclude paths starting with `file://.` and `file:///`. But still fuzz any processing that other input might have. It shouldn't be a huge problem if we do `file://mpv` for example. Not great, but also not terrible.

Kacper Michajłow committed 2 years ago

Commit bf6d49c1 parent d6803c42 files · +15 −6Browse files

Unified · Split

2 files
  1. fuzzers/fuzzer_loadfile_direct.c +14 −5
  2. fuzzers/meson.build +1 −1
fuzzers/fuzzer_loadfile_direct.c+14−5
@@ -34,18 +34,27 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 33 unmodified lines
3434 return -1;
3535
3636 #ifdef MPV_PROTO
37− if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", strlen(MPV_STRINGIFY(MPV_PROTO) "://")))
37+ if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", sizeof(MPV_STRINGIFY(MPV_PROTO) "://") - 1))
3838 return -1;
39−#else
39+#endif
40+
41+#if !defined(MPV_PROTO) || defined(MPV_PROTO_FILE)
42+ const uint8_t *data_check = data;
43+ size_t size_check = size;
44+ size_t prefix_size = sizeof("file://") - 1;
45+ if (str_startswith(data, size - 1, "file://", prefix_size)) {
46+ data_check += prefix_size;
47+ size_check -= prefix_size;
48+ }
4049 // Exclude some common paths that are not useful for testing.
4150 // Exclude -
42− if (size == 2 && !strncmp(data, "-", 1))
51+ if (size_check == 2 && !strncmp(data_check, "-", 1))
4352 return -1;
4453 // Exclude relative paths
45− if (str_startswith(data, size - 1, ".", 1))
54+ if (str_startswith(data_check, size_check - 1, ".", 1))
4655 return -1;
4756 // Exclude absolute paths
48− if (str_startswith(data, size - 1, "/", 1))
57+ if (str_startswith(data_check, size_check - 1, "/", 1))
4958 return -1;
5059 #endif
5160
fuzzers/meson.build+1−1
@@ -9,7 +9,7 @@ foreach p : ['bd', 'cdda', 'dvb', 'dvd', 'edl', 'file', 'hex', 'lavf', 'memory', · 8 unmodified lines
99 'mf', 'slice', 'smb']
1010 executable('fuzzer_protocol_' + p,
1111 'fuzzer_loadfile_direct.c',
12− c_args: ['-DMPV_PROTO=' + p],
12+ c_args: ['-DMPV_PROTO=' + p, '-DMPV_PROTO_' + p.to_upper()],
1313 include_directories: incdir,
1414 link_with: libmpv)
1515 endforeach

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