/
niceSOFT
/
util-linux
Обзор
Документация
Войти
/
niceSOFT
/
util-linux
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
libfdisk/src/fuzz.c
59 строк
1 KB
Arthur Chan
OSS-Fuzz: Add new fuzzer targets fdisk cmd
15 июн 2026, 18:47
15 июн 2026, 18:47
87c71b9
Код
Авторство
О чём код?
#include "fdiskP.h" #include "fuzz.h" #include <stdlib.h> #include <unistd.h> static int process_file(const char *name) { int rc = -1; struct fdisk_context *cxt = fdisk_new_context(); if (cxt != NULL) { if (fdisk_assign_device(cxt, name, 1) == 0) { struct fdisk_table *tb = NULL; if (fdisk_get_partitions(cxt, &tb) == 0 && tb != NULL) { size_t i, n = fdisk_table_get_nents(tb); for (i = 0; i < n; i++) fdisk_table_get_partition(tb, i); fdisk_unref_table(tb); } fdisk_deassign_device(cxt, 1); rc = 0; } fdisk_unref_context(cxt); } return rc; } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { int fd; char name[] = "/tmp/test-fdisk-fuzz.XXXXXX"; fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC); if (fd == -1) err(EXIT_FAILURE, "mkostemp() failed"); if (write(fd, data, size) != (ssize_t)size) goto out; process_file(name); out: close(fd); unlink(name); return 0; } #ifndef FUZZ_TARGET int main(int argc, char **argv) { for (int i = 1; i < argc; i++) { printf("%s ", argv[i]); if (process_file(argv[i]) == 0) printf(" OK\n"); else printf(" FAILED\n"); } } #endif