File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ set(SO_PATCH 1)
15
15
16
16
option (UTF8PROC_INSTALL "Enable installation of utf8proc" On )
17
17
option (UTF8PROC_ENABLE_TESTING "Enable testing of utf8proc" Off )
18
+ option (LIB_FUZZING_ENGINE "Fuzzing engine to link against" Off )
18
19
19
20
add_library (utf8proc
20
21
utf8proc.c
@@ -98,4 +99,12 @@ if(UTF8PROC_ENABLE_TESTING)
98
99
target_link_libraries (normtest utf8proc )
99
100
add_test (utf8proc.testgraphemetest graphemetest data/GraphemeBreakTest.txt )
100
101
add_test (utf8proc.testnormtest normtest data/NormalizationTest.txt )
102
+
103
+ if (LIB_FUZZING_ENGINE )
104
+ add_executable (fuzzer utf8proc.h test /fuzzer.c )
105
+ target_link_libraries (fuzzer ${LIB_FUZZING_ENGINE} utf8proc )
106
+ else ()
107
+ add_executable (fuzzer utf8proc.h test /fuzz_main.c test /fuzzer.c )
108
+ target_link_libraries (fuzzer utf8proc )
109
+ endif ()
101
110
endif ()
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <stdint.h>
4
+
5
+ /* Fuzz target entry point, works without libFuzzer */
6
+
7
+ int LLVMFuzzerTestOneInput (const uint8_t * data , size_t size );
8
+
9
+ int main (int argc , char * * argv )
10
+ {
11
+ FILE * f ;
12
+ char * buf = NULL ;
13
+ long siz_buf ;
14
+
15
+ if (argc < 2 )
16
+ {
17
+ fprintf (stderr , "no input file\n" );
18
+ goto err ;
19
+ }
20
+
21
+ f = fopen (argv [1 ], "rb" );
22
+ if (f == NULL )
23
+ {
24
+ fprintf (stderr , "error opening input file %s\n" , argv [1 ]);
25
+ goto err ;
26
+ }
27
+
28
+ fseek (f , 0 , SEEK_END );
29
+
30
+ siz_buf = ftell (f );
31
+ rewind (f );
32
+
33
+ if (siz_buf < 1 ) goto err ;
34
+
35
+ buf = (char * )malloc (siz_buf );
36
+ if (buf == NULL )
37
+ {
38
+ fprintf (stderr , "malloc() failed\n" );
39
+ goto err ;
40
+ }
41
+
42
+ if (fread (buf , siz_buf , 1 , f ) != 1 )
43
+ {
44
+ fprintf (stderr , "fread() failed\n" );
45
+ goto err ;
46
+ }
47
+
48
+ (void )LLVMFuzzerTestOneInput ((uint8_t * )buf , siz_buf );
49
+
50
+ err :
51
+ free (buf );
52
+
53
+ return 0 ;
54
+ }
Original file line number Diff line number Diff line change
1
+ #include <utf8proc.h>
2
+
3
+ int LLVMFuzzerTestOneInput (const uint8_t * data , size_t size )
4
+ {
5
+ if (size < 1 ) return 0 ;
6
+
7
+ if (data [size - 1 ] != '\0' ) return 0 ;
8
+
9
+ free (utf8proc_NFD (data ));
10
+ free (utf8proc_NFC (data ));
11
+ free (utf8proc_NFKD (data ));
12
+ free (utf8proc_NFKC (data ));
13
+ free (utf8proc_NFKC_Casefold (data ));
14
+
15
+ return 0 ;
16
+ }
Original file line number Diff line number Diff line change
1
+ #! /bin/bash -eu
2
+ # This script is meant to be run by
3
+ # https://github.com/google/oss-fuzz/blob/master/projects/utf8proc/Dockerfile
4
+
5
+ mkdir build
6
+ cd build
7
+ cmake .. -DUTF8PROC_ENABLE_TESTING=ON -DLIB_FUZZING_ENGINE=" $LIB_FUZZING_ENGINE "
8
+ make -j$( nproc)
9
+
10
+ cp $SRC /utf8proc/build/fuzzer utf8proc_fuzzer
11
+
12
+ find $SRC /utf8proc/test -name " *.txt" | \
13
+ xargs zip $OUT /utf8proc_fuzzer_seed_corpus.zip
You can’t perform that action at this time.
0 commit comments