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