1
+ /* Copyright 2021 Samsung Electronics Co., Ltd. and other contributors
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ #include <stdint.h>
17
+ #include <string.h>
18
+ #include <stdlib.h>
19
+ #include <stdio.h>
20
+
21
+ int
22
+ LLVMFuzzerTestOneInput (const uint8_t * data , size_t size )
23
+ {
24
+ if (size < 20 ) {
25
+ return 0 ;
26
+ }
27
+
28
+ // Skip test cases with double quotes
29
+ for (int i = 0 ; i < size ; i ++ ) {
30
+ if (data [i ]== 34 ) {
31
+ return 0 ;
32
+ }
33
+ }
34
+
35
+ // Create javascript file
36
+ char filename [256 ];
37
+ sprintf (filename , "/tmp/libfuzzer.js" );
38
+
39
+ // Create javascript code
40
+ char one [] = "(new Buffer(\"" ;
41
+ char two [] = "\")).slice(0, 1).readUInt16LE({}, true);');\n" ;
42
+ FILE * fp = fopen (filename , "wb" );
43
+ if (!fp )
44
+ return 0 ;
45
+ fwrite (one , sizeof (char ), strlen (one ), fp );
46
+ fwrite (data , size , 1 , fp );
47
+ fwrite (two , sizeof (char ), strlen (two ), fp );
48
+ fclose (fp );
49
+
50
+ int argc = 2 ;
51
+ char * argv [argc ];
52
+ argv [0 ] = "iotjs" ;
53
+ argv [1 ] = "/tmp/libfuzzer.js" ;
54
+
55
+ iotjs_entry (argc , argv );
56
+
57
+ unlink (filename );
58
+ return 0 ;
59
+ }
0 commit comments