Skip to content

Commit

Permalink
moved to multiline strings in tests to make it easier to extract them…
Browse files Browse the repository at this point in the history
… for fuzzing corpus
  • Loading branch information
d4l3k committed May 3, 2018
1 parent ea71532 commit c0207ec
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 53 deletions.
27 changes: 23 additions & 4 deletions pry-build-corpus/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package main

import (
"bytes"
"crypto/sha1"
"encoding/hex"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
)

const out = "fuzz/corpus/"

var (
exampleRegexpQuotes = regexp.MustCompile("InterpretString\\((\"(.*)\"|`(.*)`)\\)")
exampleRegexpQuotes = regexp.MustCompile("(?s)InterpretString\\(`(.*?)`\\)")
)

func main() {
Expand All @@ -24,14 +28,29 @@ func run() error {
if err != nil {
return err
}
if err := os.MkdirAll(out, 0755); err != nil {
return err
}
for _, fpath := range files {
body, err := ioutil.ReadFile(fpath)
if err != nil {
return err
}
matches := exampleRegexpQuotes.FindAllSubmatch(body, -1)
for _, match := range matches {
expr := match[2]

for {
match := exampleRegexpQuotes.FindSubmatchIndex(body)
if match == nil {
break
}

expr := bytes.TrimSpace(body[match[2]:match[3]])
hash := sha1.Sum(expr)
file := hex.EncodeToString(hash[:])
if err := ioutil.WriteFile(filepath.Join(out, file), expr, 0644); err != nil {
return err
}

body = body[match[1]:]
}
}
return nil
Expand Down
Loading

0 comments on commit c0207ec

Please sign in to comment.