1 #define _GNU_SOURCE 2 #include <stdio.h> 3 #include <stdint.h> 4 #include <stdlib.h> 5 #include <stddef.h> 6 #include <string.h> 7 #include <fcntl.h> 8 #include <errno.h> 9 #include <unistd.h> 10 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 14 #include "uci.h" 15 16 static void fuzz_uci_import(const uint8_t *input, size_t size) 17 { 18 int r; 19 int fd; 20 FILE *fs = NULL; 21 struct uci_context *ctx = NULL; 22 struct uci_package *package = NULL; 23 24 fd = open("/dev/shm", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); 25 if (fd < 0) { 26 perror("unable to create temp file"); 27 exit(-1); 28 } 29 30 r = write(fd, input, size); 31 if (r < 0) { 32 perror("unable to write()"); 33 exit(-1); 34 } 35 36 fs = fdopen(fd, "r"); 37 if (fs == NULL) { 38 perror("unable to fdopen()"); 39 exit(-1); 40 } 41 42 fseek(fs, 0L, SEEK_SET); 43 44 ctx = uci_alloc_context(); 45 if (ctx == NULL) { 46 perror("unable to uci_alloc_context()"); 47 exit(-1); 48 } 49 50 uci_import(ctx, fs, NULL, &package, false); 51 uci_free_context(ctx); 52 close(fd); 53 fclose(fs); 54 } 55 56 int LLVMFuzzerTestOneInput(const uint8_t *input, size_t size) 57 { 58 fuzz_uci_import(input, size); 59 return 0; 60 } 61
This page was automatically generated by LXR 0.3.1. • OpenWrt