mirror of
https://github.com/projectdiscovery/httpx
synced 2026-06-08 16:50:17 +00:00
fix: improve error handling and fix bugs (#2499)
* code quality: improve error handling and fix bugs - Fix bug: return err instead of closeErr in DecodeData error path (httpx.go) - Improve error handling for strconv.Atoi calls in multiple locations - Change hammingDistanceThreshold from var to const since it's never modified - Fix redundant return statement in ListFilesWithPattern - Improve port parsing to handle empty port strings explicitly * runner: keep input counters incrementing under -skip-dedupe Revert the defensive strconv.Atoi guard around the SkipDedupe branches: values stored in r.hm are always integer strings written by this same code path, so the parseErr/cnt>0 check is unreachable in practice, and when taken literally it skipped the numHosts/numTargets increment for duplicate inputs. --------- Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
This commit is contained in:
@@ -52,7 +52,7 @@ func ListFilesWithPattern(rootpattern string) ([]string, error) {
|
||||
if len(files) == 0 {
|
||||
return nil, errors.New("no files found")
|
||||
}
|
||||
return files, err
|
||||
return files, nil
|
||||
}
|
||||
|
||||
// FileNameIsGlob check if the filanem is a pattern
|
||||
|
||||
@@ -75,8 +75,11 @@ func Jarm(dialer *fastdialer.Dialer, host string, duration int) string {
|
||||
return ""
|
||||
}
|
||||
t.Host = u.Hostname()
|
||||
port, _ := strconv.Atoi(u.Port())
|
||||
t.Port = port
|
||||
if portStr := u.Port(); portStr != "" {
|
||||
if p, err := strconv.Atoi(portStr); err == nil {
|
||||
t.Port = p
|
||||
}
|
||||
}
|
||||
}
|
||||
if t.Port == 0 {
|
||||
t.Port = defaultPort
|
||||
|
||||
@@ -293,7 +293,7 @@ get_response:
|
||||
|
||||
respbody, err = DecodeData(respbody, httpresp.Header)
|
||||
if err != nil && !shouldIgnoreBodyErrors {
|
||||
return nil, closeErr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
respbodystr := string(respbody)
|
||||
@@ -307,8 +307,9 @@ get_response:
|
||||
if resp.ContentLength <= 0 {
|
||||
// check if it's in the header and convert to int
|
||||
if contentLength, ok := resp.Headers["Content-Length"]; ok && len(contentLength) > 0 {
|
||||
contentLengthInt, _ := strconv.Atoi(contentLength[0])
|
||||
resp.ContentLength = contentLengthInt
|
||||
if contentLengthInt, err := strconv.Atoi(contentLength[0]); err == nil {
|
||||
resp.ContentLength = contentLengthInt
|
||||
}
|
||||
}
|
||||
|
||||
// if we have a body, then use the number of bytes in the body if the length is still zero
|
||||
|
||||
+7
-2
@@ -125,7 +125,7 @@ func (r *Runner) IsInterrupted() bool {
|
||||
}
|
||||
|
||||
// picked based on try-fail but it seems to close to one it's used https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html#c1992
|
||||
var hammingDistanceThreshold int = 22
|
||||
const hammingDistanceThreshold = 22
|
||||
|
||||
// regex for stripping ANSI codes
|
||||
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
||||
@@ -2204,7 +2204,12 @@ retry:
|
||||
|
||||
pipeline := false
|
||||
if scanopts.Pipeline {
|
||||
port, _ := strconv.Atoi(URL.Port())
|
||||
port := 0
|
||||
if portStr := URL.Port(); portStr != "" {
|
||||
if p, err := strconv.Atoi(portStr); err == nil {
|
||||
port = p
|
||||
}
|
||||
}
|
||||
r.ratelimiter.Take()
|
||||
pipeline = hp.SupportPipeline(protocol, method, URL.Host, port)
|
||||
if pipeline {
|
||||
|
||||
Reference in New Issue
Block a user