Skip to content

Commit

Permalink
Merge pull request #9 from 0x19/solc-sync
Browse files Browse the repository at this point in the history
Collosal Fix: Download releases over curl instead of go http...
  • Loading branch information
0x19 committed Mar 28, 2024
2 parents faf5507 + 670cf94 commit 60e0ba7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
args: --exclude=G302 ./...
2 changes: 1 addition & 1 deletion .github/workflows/goveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
go:
- '1.19'
- '1.22'

steps:
- uses: actions/setup-go@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.22'

- name: Checkout submodules
run: make submodules
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/0x19/solc-switch

go 1.19
go 1.22

require (
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions releases/releases.json
Git LFS file not shown
37 changes: 9 additions & 28 deletions syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math/big"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -103,6 +104,7 @@ func (s *Solc) SyncBinaries(versions []Version, limitVersion string) error {

for _, asset := range version.Assets {
distribution := s.GetDistributionForAsset()

if strings.Contains(asset.Name, distribution) {
filename := fmt.Sprintf("%s/solc-%s", s.config.GetReleasesPath(), versionTag)
if distribution == "solc-windows" {
Expand Down Expand Up @@ -236,38 +238,17 @@ func (s *Solc) downloadFile(file string, url string) error {
// Just a bit of the time because we could receive 503 from GitHub so we don't want to spam them
randomDelayBetween500And1500()

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}

req.Header.Add("Authorization", fmt.Sprintf("token %s", s.config.personalAccessToken))
req = req.WithContext(s.ctx)

resp, err := s.GetHTTPClient().Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download file: %s", resp.Status)
}

out, err := os.Create(filepath.Clean(file))
if err != nil {
return err
}
defer out.Close()
// Construct the curl command
curlCmd := exec.Command("curl", "-s", "-L", url, "-o", file)
curlCmd.Stderr = os.Stderr

if _, err = io.Copy(out, resp.Body); err != nil {
return err
// Execute curl
if err := curlCmd.Run(); err != nil {
return fmt.Errorf("curl command failed: %v", err)
}

// #nosec G302
// G302 (CWE-276): Expect file permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM)
// We want executable files to be executable by the user running the program so we can't use 0600.
if err := os.Chmod(file, 0700); err != nil {
if err := os.Chmod(file, 0755); err != nil {
return fmt.Errorf("failed to set file as executable: %v", err)
}

Expand Down

0 comments on commit 60e0ba7

Please sign in to comment.