Skip to content

Commit

Permalink
excluding compilation platform fallsback to default (#362)
Browse files Browse the repository at this point in the history
* fix: excluding compilation platform fallsback to default

* warn if coverage is disabled

---------

Co-authored-by: anishnaik <anish.naik@trailofbits.com>
  • Loading branch information
2 people authored and s4nsec committed Jul 8, 2024
1 parent 8320d6e commit 3259c27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions cmd/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cmd

import (
"fmt"
"github.com/crytic/medusa/cmd/exitcodes"
"github.com/crytic/medusa/logging/colors"
"os"
"os/signal"
"path/filepath"

"github.com/crytic/medusa/cmd/exitcodes"
"github.com/crytic/medusa/logging/colors"

"github.com/crytic/medusa/fuzzing"
"github.com/crytic/medusa/fuzzing/config"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -102,7 +103,8 @@ func cmdRunFuzz(cmd *cobra.Command, args []string) error {
if existenceError == nil {
// Try to read the configuration file and throw an error if something goes wrong
cmdLogger.Info("Reading the configuration file at: ", colors.Bold, configPath, colors.Reset)
projectConfig, err = config.ReadProjectConfigFromFile(configPath)
// Use the default compilation platform if the config file doesn't specify one
projectConfig, err = config.ReadProjectConfigFromFile(configPath, DefaultCompilationPlatform)
if err != nil {
cmdLogger.Error("Failed to run the fuzz command", err)
return err
Expand Down Expand Up @@ -144,6 +146,10 @@ func cmdRunFuzz(cmd *cobra.Command, args []string) error {
return err
}

if !projectConfig.Fuzzing.CoverageEnabled {
cmdLogger.Warn("Disabling coverage may limit efficacy of fuzzing. Consider enabling coverage for better results.")
}

// Create our fuzzing
fuzzer, fuzzErr := fuzzing.NewFuzzer(*projectConfig)
if fuzzErr != nil {
Expand Down
9 changes: 5 additions & 4 deletions fuzzing/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package config
import (
"encoding/json"
"errors"
"math/big"
"os"

"github.com/crytic/medusa/chain/config"
"github.com/crytic/medusa/compilation"
"github.com/crytic/medusa/logging"
"github.com/crytic/medusa/utils"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/rs/zerolog"
"math/big"
"os"
)

// The following directives will be picked up by the `go generate` command to generate JSON marshaling code from
Expand Down Expand Up @@ -242,15 +243,15 @@ type FileLoggingConfig struct {

// ReadProjectConfigFromFile reads a JSON-serialized ProjectConfig from a provided file path.
// Returns the ProjectConfig if it succeeds, or an error if one occurs.
func ReadProjectConfigFromFile(path string) (*ProjectConfig, error) {
func ReadProjectConfigFromFile(path string, platform string) (*ProjectConfig, error) {
// Read our project configuration file data
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}

// Parse the project configuration
projectConfig, err := GetDefaultProjectConfig("")
projectConfig, err := GetDefaultProjectConfig(platform)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3259c27

Please sign in to comment.