Skip to content

Commit 70ac8bf

Browse files
Merge pull request projectdiscovery#7018 from projectdiscovery/dwisiswant0/chore/go-fix
chore: `golangci-lint run --fix ./...`
2 parents bde0272 + 1556d08 commit 70ac8bf

File tree

12 files changed

+33
-39
lines changed

12 files changed

+33
-39
lines changed

internal/runner/healthcheck.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
func DoHealthCheck(options *types.Options) string {
1616
// RW permissions on config file
1717
var test strings.Builder
18-
test.WriteString(fmt.Sprintf("Version: %s\n", config.Version))
19-
test.WriteString(fmt.Sprintf("Operating System: %s\n", runtime.GOOS))
20-
test.WriteString(fmt.Sprintf("Architecture: %s\n", runtime.GOARCH))
21-
test.WriteString(fmt.Sprintf("Go Version: %s\n", runtime.Version()))
22-
test.WriteString(fmt.Sprintf("Compiler: %s\n", runtime.Compiler))
18+
fmt.Fprintf(&test, "Version: %s\n", config.Version)
19+
fmt.Fprintf(&test, "Operating System: %s\n", runtime.GOOS)
20+
fmt.Fprintf(&test, "Architecture: %s\n", runtime.GOARCH)
21+
fmt.Fprintf(&test, "Go Version: %s\n", runtime.Version())
22+
fmt.Fprintf(&test, "Compiler: %s\n", runtime.Compiler)
2323

2424
var testResult string
2525
cfg := config.DefaultConfig
@@ -33,7 +33,7 @@ func DoHealthCheck(options *types.Options) string {
3333
if err != nil {
3434
testResult += fmt.Sprintf(" (%s)", err)
3535
}
36-
test.WriteString(fmt.Sprintf("File \"%s\" Read => %s\n", filename, testResult))
36+
fmt.Fprintf(&test, "File \"%s\" Read => %s\n", filename, testResult)
3737
ok, err = fileutil.IsWriteable(filename)
3838
if ok {
3939
testResult = "Ok"
@@ -43,7 +43,7 @@ func DoHealthCheck(options *types.Options) string {
4343
if err != nil {
4444
testResult += fmt.Sprintf(" (%s)", err)
4545
}
46-
test.WriteString(fmt.Sprintf("File \"%s\" Write => %s\n", filename, testResult))
46+
fmt.Fprintf(&test, "File \"%s\" Write => %s\n", filename, testResult)
4747
}
4848
c4, err := net.Dial("tcp4", "scanme.sh:80")
4949
if err == nil && c4 != nil {
@@ -53,7 +53,7 @@ func DoHealthCheck(options *types.Options) string {
5353
if err != nil {
5454
testResult = fmt.Sprintf("Ko (%s)", err)
5555
}
56-
test.WriteString(fmt.Sprintf("IPv4 connectivity to scanme.sh:80 => %s\n", testResult))
56+
fmt.Fprintf(&test, "IPv4 connectivity to scanme.sh:80 => %s\n", testResult)
5757
c6, err := net.Dial("tcp6", "scanme.sh:80")
5858
if err == nil && c6 != nil {
5959
_ = c6.Close()
@@ -62,7 +62,7 @@ func DoHealthCheck(options *types.Options) string {
6262
if err != nil {
6363
testResult = fmt.Sprintf("Ko (%s)", err)
6464
}
65-
test.WriteString(fmt.Sprintf("IPv6 connectivity to scanme.sh:80 => %s\n", testResult))
65+
fmt.Fprintf(&test, "IPv6 connectivity to scanme.sh:80 => %s\n", testResult)
6666
u4, err := net.Dial("udp4", "scanme.sh:53")
6767
if err == nil && u4 != nil {
6868
_ = u4.Close()
@@ -71,7 +71,7 @@ func DoHealthCheck(options *types.Options) string {
7171
if err != nil {
7272
testResult = fmt.Sprintf("Ko (%s)", err)
7373
}
74-
test.WriteString(fmt.Sprintf("IPv4 UDP connectivity to scanme.sh:53 => %s\n", testResult))
74+
fmt.Fprintf(&test, "IPv4 UDP connectivity to scanme.sh:53 => %s\n", testResult)
7575

7676
return test.String()
7777
}

lib/sdk_private.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (e *NucleiEngine) applyRequiredDefaults(ctx context.Context) {
5151
return
5252
}
5353
sb := strings.Builder{}
54-
sb.WriteString(fmt.Sprintf("[%v] ", event.TemplateID))
54+
fmt.Fprintf(&sb, "[%v] ", event.TemplateID)
5555
if event.Matched != "" {
5656
sb.WriteString(event.Matched)
5757
} else {

pkg/fuzz/analyzers/time/time_delay.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ func checkTimingDependency(
9898
result := regression.IsWithinConfidence(correlationErrorRange, 1.0, slopeErrorRange)
9999
if result {
100100
var resultReason strings.Builder
101-
resultReason.WriteString(fmt.Sprintf(
102-
"[time_delay] made %d requests (baseline: %.2fs) successfully, with a regression slope of %.2f and correlation %.2f",
101+
fmt.Fprintf(&resultReason, "[time_delay] made %d requests (baseline: %.2fs) successfully, with a regression slope of %.2f and correlation %.2f",
103102
requestsLimit,
104103
baselineDelay,
105104
regression.slope,
106-
regression.correlation,
107-
))
105+
regression.correlation)
108106
for _, request := range requestsSent {
109-
resultReason.WriteString(fmt.Sprintf("\n - delay: %ds, delayReceived: %fs", request.delay, request.delayReceived))
107+
fmt.Fprintf(&resultReason, "\n - delay: %ds, delayReceived: %fs", request.delay, request.delayReceived)
110108
}
111109
return result, resultReason.String(), nil
112110
}

pkg/js/devtools/scrapefuncs/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ iconType: "solid"
168168
for _, sig := range f.Signatures {
169169
sigSlice = append(sigSlice, "`"+sig+"`")
170170
}
171-
sb.WriteString(fmt.Sprintf("| %s | %s | %s |\n", f.Name, f.Description, strings.Join(sigSlice, ", ")))
171+
fmt.Fprintf(&sb, "| %s | %s | %s |\n", f.Name, f.Description, strings.Join(sigSlice, ", "))
172172
}
173173
sb.WriteString("\n")
174174
}

pkg/js/devtools/tsgen/cmd/tsgen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func main() {
9999
// generating index.ts file
100100
var buff bytes.Buffer
101101
for _, dir := range dirs {
102-
buff.WriteString(fmt.Sprintf("export * as %s from './%s';\n", filepath.Base(dir), filepath.Base(dir)))
102+
fmt.Fprintf(&buff, "export * as %s from './%s';\n", filepath.Base(dir), filepath.Base(dir))
103103
}
104104
_ = os.WriteFile(filepath.Join(out, "index.ts"), buff.Bytes(), 0755)
105105
}

pkg/js/libs/ldap/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ func DecodeSID(s string) string {
219219

220220
var builder strings.Builder
221221
builder.WriteString("S-")
222-
builder.WriteString(fmt.Sprintf("%d-", revisionLvl))
223-
builder.WriteString(fmt.Sprintf("%d", authority))
222+
fmt.Fprintf(&builder, "%d-", revisionLvl)
223+
fmt.Fprintf(&builder, "%d", authority)
224224
for _, v := range subAuthorities {
225-
builder.WriteString(fmt.Sprintf("-%d", v))
225+
fmt.Fprintf(&builder, "-%d", v)
226226
}
227227
return builder.String()
228228
}

pkg/js/libs/mysql/mysql_private.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func BuildDSN(opts MySQLOptions) (string, error) {
6060
}
6161
target := net.JoinHostPort(opts.Host, fmt.Sprintf("%d", opts.Port))
6262
var dsn strings.Builder
63-
dsn.WriteString(fmt.Sprintf("%v:%v", url.QueryEscape(opts.Username), opts.Password))
63+
fmt.Fprintf(&dsn, "%v:%v", url.QueryEscape(opts.Username), opts.Password)
6464
dsn.WriteString("@")
65-
dsn.WriteString(fmt.Sprintf("%v(%v)", opts.Protocol, target))
65+
fmt.Fprintf(&dsn, "%v(%v)", opts.Protocol, target)
6666
if opts.DbName != "" {
6767
dsn.WriteString(opts.DbName)
6868
}

pkg/protocols/headless/engine/engine.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ import (
1515
"github.com/projectdiscovery/nuclei/v3/pkg/types"
1616
fileutil "github.com/projectdiscovery/utils/file"
1717
osutils "github.com/projectdiscovery/utils/os"
18-
processutil "github.com/projectdiscovery/utils/process"
1918
)
2019

2120
// Browser is a browser structure for nuclei headless module
2221
type Browser struct {
2322
customAgent string
2423
defaultHeaders map[string]string
2524
tempDir string
26-
previousPIDs map[int32]struct{} // track already running PIDs
2725
engine *rod.Browser
2826
options *types.Options
2927
launcher *launcher.Launcher
@@ -36,14 +34,11 @@ type Browser struct {
3634
// New creates a new nuclei headless browser module
3735
func New(options *types.Options) (*Browser, error) {
3836
var launcherURL, dataStore string
39-
var previousPIDs map[int32]struct{}
4037
var err error
4138

4239
chromeLauncher := launcher.New()
4340

4441
if options.CDPEndpoint == "" {
45-
previousPIDs = processutil.FindProcesses(processutil.IsChromeProcess)
46-
4742
dataStore, err = os.MkdirTemp("", "nuclei-*")
4843
if err != nil {
4944
return nil, errors.Wrap(err, "could not create temporary directory")
@@ -135,7 +130,6 @@ func New(options *types.Options) (*Browser, error) {
135130
httpClientOnce: &sync.Once{},
136131
launcher: chromeLauncher,
137132
}
138-
engine.previousPIDs = previousPIDs
139133
return engine, nil
140134
}
141135

@@ -199,5 +193,4 @@ func (b *Browser) Close() {
199193
_ = b.engine.Close()
200194
b.launcher.Kill()
201195
_ = os.RemoveAll(b.tempDir)
202-
processutil.CloseProcesses(processutil.IsChromeProcess, b.previousPIDs)
203196
}

pkg/protocols/headless/engine/page_actions_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ func TestActionNavigate(t *testing.T) {
4141

4242
testHeadlessSimpleResponse(t, response, actions, 60*time.Second, func(page *Page, err error, out ActionData) {
4343
require.Nilf(t, err, "could not run page actions")
44-
require.Equal(t, "Nuclei Test Page", page.Page().MustInfo().Title, "could not navigate correctly")
44+
require.NotNil(t, page, "page should not be nil")
45+
info, infoErr := page.Page().Info()
46+
require.NoError(t, infoErr, "could not fetch page info")
47+
require.Equal(t, "Nuclei Test Page", info.Title, "could not navigate correctly")
4548
})
4649
}
4750

pkg/protocols/headless/engine/rules.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (p *Page) routingRuleHandler(httpClient *http.Client) func(ctx *rod.Hijack)
8888
var rawResp strings.Builder
8989
respPayloads := ctx.Response.Payload()
9090
if respPayloads != nil {
91-
rawResp.WriteString(fmt.Sprintf("HTTP/1.1 %d %s\n", respPayloads.ResponseCode, respPayloads.ResponsePhrase))
91+
fmt.Fprintf(&rawResp, "HTTP/1.1 %d %s\n", respPayloads.ResponseCode, respPayloads.ResponsePhrase)
9292
for _, header := range respPayloads.ResponseHeaders {
9393
rawResp.WriteString(header.Name + ": " + header.Value + "\n")
9494
}
@@ -126,17 +126,17 @@ func (p *Page) routingRuleHandlerNative(e *proto.FetchRequestPaused) error {
126126

127127
// attempts to rebuild request
128128
var rawReq strings.Builder
129-
rawReq.WriteString(fmt.Sprintf("%s %s %s\n", e.Request.Method, e.Request.URL, "HTTP/1.1"))
129+
fmt.Fprintf(&rawReq, "%s %s %s\n", e.Request.Method, e.Request.URL, "HTTP/1.1")
130130
for _, header := range e.Request.Headers {
131-
rawReq.WriteString(fmt.Sprintf("%s\n", header.String()))
131+
fmt.Fprintf(&rawReq, "%s\n", header.String())
132132
}
133133
if e.Request.HasPostData {
134-
rawReq.WriteString(fmt.Sprintf("\n%s\n", e.Request.PostData))
134+
fmt.Fprintf(&rawReq, "\n%s\n", e.Request.PostData)
135135
}
136136

137137
// attempts to rebuild the response
138138
var rawResp strings.Builder
139-
rawResp.WriteString(fmt.Sprintf("HTTP/1.1 %d %s\n", statusCode, e.ResponseStatusText))
139+
fmt.Fprintf(&rawResp, "HTTP/1.1 %d %s\n", statusCode, e.ResponseStatusText)
140140
for _, header := range e.ResponseHeaders {
141141
rawResp.WriteString(header.Name + ": " + header.Value + "\n")
142142
}

0 commit comments

Comments
 (0)