Nothing should ever modify this data. Also, add CLOEXEC for good measure.
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | #include <stdlib.h> |
| 20 | 20 | #include <string.h> |
| 21 | 21 | |
| 22 | +#include <fcntl.h> | |
| 22 | 23 | #include <sys/mman.h> |
| 23 | 24 | #include <unistd.h> |
| 24 | 25 | |
| @@ -41,7 +42,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 16 unmodified lines | ||
| 41 | 42 | #endif |
| 42 | 43 | |
| 43 | 44 | // fmemopen doesn't have associated file descriptor, so we do copy. |
| 44 | − int fd = memfd_create("fuzz_mpv_load", 0); | |
| 45 | + int fd = memfd_create("fuzz_mpv_load", MFD_CLOEXEC | MFD_ALLOW_SEALING); | |
| 45 | 46 | if (fd == -1) |
| 46 | 47 | exit(1); |
| 47 | 48 | ssize_t written = 0; |
| @@ -51,6 +52,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 3 unmodified lines | ||
| 51 | 52 | exit(1); |
| 52 | 53 | written += result; |
| 53 | 54 | } |
| 55 | + if (fcntl(fd, F_ADD_SEALS, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_SEAL) != 0) | |
| 56 | + exit(1); | |
| 54 | 57 | if (lseek(fd, 0, SEEK_SET) != 0) |
| 55 | 58 | exit(1); |
| 56 | 59 | char filename[5 + 10 + 1]; |