1 // Copyright 2021 Google LLC 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 17 import com.code_intelligence.jazzer.api.FuzzedDataProvider; 18 19 import static com.github.javaparser.ParseStart.COMPILATION_UNIT; 20 import com.github.javaparser.JavaParser; 21 import com.github.javaparser.ParseResult; 22 import com.github.javaparser.ast.CompilationUnit; 23 import com.github.javaparser.ParserConfiguration; 24 import static com.github.javaparser.Providers.provider; 25 26 import java.io.ByteArrayInputStream; 27 import java.io.InputStream; 28 29 public class parseFuzzer { fuzzerTestOneInput(FuzzedDataProvider data)30 public static void fuzzerTestOneInput(FuzzedDataProvider data) { 31 String datastring = data.consumeRemainingAsString(); 32 InputStream datastream = new ByteArrayInputStream(datastring.getBytes()); 33 try { 34 ParserConfiguration configuration = new ParserConfiguration(); 35 final ParseResult<CompilationUnit> result = new JavaParser(configuration) 36 .parse(COMPILATION_UNIT, provider(datastream, configuration.getCharacterEncoding())); 37 } catch (Exception e) { 38 return; 39 } 40 } 41 } 42