mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 17:25:28 +00:00
Merge pull request #6321 from hdm/bug/various-race-conditions
Address race conditions in http.Request and MemGuardian
This commit is contained in:
commit
3e9bee7400
@ -16,9 +16,12 @@ var (
|
||||
MaxBytesBufferAllocOnLowMemory = env.GetEnvOrDefault("MEMGUARDIAN_ALLOC", 0)
|
||||
memTimer *time.Ticker
|
||||
cancelFunc context.CancelFunc
|
||||
muGlobalChange sync.Mutex
|
||||
)
|
||||
|
||||
func StartActiveMemGuardian(ctx context.Context) {
|
||||
muGlobalChange.Lock()
|
||||
defer muGlobalChange.Unlock()
|
||||
if memguardian.DefaultMemGuardian == nil || memTimer != nil {
|
||||
return
|
||||
}
|
||||
@ -42,6 +45,9 @@ func StartActiveMemGuardian(ctx context.Context) {
|
||||
}
|
||||
|
||||
func StopActiveMemGuardian() {
|
||||
muGlobalChange.Lock()
|
||||
defer muGlobalChange.Unlock()
|
||||
|
||||
if memguardian.DefaultMemGuardian == nil {
|
||||
return
|
||||
}
|
||||
@ -73,8 +79,6 @@ func GuardThreadsOrDefault(current int) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
var muGlobalChange sync.Mutex
|
||||
|
||||
// Global setting
|
||||
func GlobalGuardBytesBufferAlloc() error {
|
||||
if !muGlobalChange.TryLock() {
|
||||
|
||||
@ -864,8 +864,10 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ
|
||||
var curlCommand string
|
||||
if !request.Unsafe && resp != nil && generatedRequest.request != nil && resp.Request != nil && !request.Race {
|
||||
bodyBytes, _ := generatedRequest.request.BodyBytes()
|
||||
resp.Request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||
command, err := http2curl.GetCurlCommand(generatedRequest.request.Request)
|
||||
// Use a clone to avoid a race condition with the http transport
|
||||
req := resp.Request.Clone(resp.Request.Context())
|
||||
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||
command, err := http2curl.GetCurlCommand(req)
|
||||
if err == nil && command != nil {
|
||||
curlCommand = command.String()
|
||||
}
|
||||
|
||||
@ -12,7 +12,8 @@ import (
|
||||
// dump creates a dump of the http request in form of a byte slice
|
||||
func dump(req *generatedRequest, reqURL string) ([]byte, error) {
|
||||
if req.request != nil {
|
||||
bin, err := req.request.Dump()
|
||||
// Use a clone to avoid a race condition with the http transport
|
||||
bin, err := req.request.Clone(req.request.Context()).Dump()
|
||||
if err != nil {
|
||||
return nil, errorutil.NewWithErr(err).WithTag("http").Msgf("could not dump request: %v", req.request.String())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user