blob: 9134d7628ec9dbff2f2651943c76a00350375726 [file] [log] [blame]
Kirill Bobyrevade2e572018-08-20 07:00:36 +00001//===--- special-case-list-fuzzer.cpp - Fuzzer for special case lists -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ADT/StringRef.h"
11#include "llvm/Support/Regex.h"
12#include "llvm/Support/YAMLTraits.h"
13#include <cassert>
14#include <string>
15
16llvm::Regex Infinity("^[-+]?(\\.inf|\\.Inf|\\.INF)$");
17llvm::Regex Base8("^0o[0-7]+$");
18llvm::Regex Base16("^0x[0-9a-fA-F]+$");
19llvm::Regex Float("^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
20
21inline bool isNumericRegex(llvm::StringRef S) {
22
23 if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
24 return true;
25
26 if (Infinity.match(S))
27 return true;
28
29 if (Base8.match(S))
30 return true;
31
32 if (Base16.match(S))
33 return true;
34
35 if (Float.match(S))
36 return true;
37
38 return false;
39}
40
41extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
42 std::string Input(reinterpret_cast<const char *>(Data), Size);
43 Input.erase(std::remove(Input.begin(), Input.end(), 0), Input.end());
44 if (!Input.empty() && llvm::yaml::isNumeric(Input) != isNumericRegex(Input))
Simon Pilgrimf90beef2018-08-20 09:49:20 +000045 LLVM_BUILTIN_TRAP;
Kirill Bobyrevade2e572018-08-20 07:00:36 +000046 return 0;
47}