mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
fix: unaligned 64-bit atomic operation panic (#1696)
This commit is contained in:
1 parent
a211b1601f
commit
977236cb5f
2 files changed
+4
-5
No files matched your search
+1
-2
@@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@@ -362,7 +361,7 @@ func bytesConvert(bytes uint64) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findingSummaryAndExit(detector *detect.Detector, findings []report.Finding, exitCode int, start time.Time, err error) {
|
func findingSummaryAndExit(detector *detect.Detector, findings []report.Finding, exitCode int, start time.Time, err error) {
|
||||||
totalBytes := atomic.LoadUint64(&detector.TotalBytes)
|
totalBytes := detector.TotalBytes.Load()
|
||||||
bytesMsg := fmt.Sprintf("scanned ~%d bytes (%s)", totalBytes, bytesConvert(totalBytes))
|
bytesMsg := fmt.Sprintf("scanned ~%d bytes (%s)", totalBytes, bytesConvert(totalBytes))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logging.Info().Msgf("%s in %s", bytesMsg, FormatDuration(time.Since(start)))
|
logging.Info().Msgf("%s in %s", bytesMsg, FormatDuration(time.Since(start)))
|
||||||
|
|||||||
+3
-3
@@ -89,7 +89,7 @@ type Detector struct {
|
|||||||
ReportPath string
|
ReportPath string
|
||||||
Reporter report.Reporter
|
Reporter report.Reporter
|
||||||
|
|
||||||
TotalBytes uint64
|
TotalBytes atomic.Uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fragment contains the data to be scanned
|
// Fragment contains the data to be scanned
|
||||||
@@ -184,9 +184,9 @@ func (d *Detector) DetectString(content string) []report.Finding {
|
|||||||
// Detect scans the given fragment and returns a list of findings
|
// Detect scans the given fragment and returns a list of findings
|
||||||
func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
func (d *Detector) Detect(fragment Fragment) []report.Finding {
|
||||||
if fragment.Bytes == nil {
|
if fragment.Bytes == nil {
|
||||||
atomic.AddUint64(&d.TotalBytes, uint64(len(fragment.Raw)))
|
d.TotalBytes.Add(uint64(len(fragment.Raw)))
|
||||||
}
|
}
|
||||||
atomic.AddUint64(&d.TotalBytes, uint64(len(fragment.Bytes)))
|
d.TotalBytes.Add(uint64(len(fragment.Bytes)))
|
||||||
|
|
||||||
var findings []report.Finding
|
var findings []report.Finding
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user