mirror of
https://github.com/securego/gosec.git
synced 2025-11-23 22:15:04 +02:00
Small update to G201 and added ConcatString Function (#228)
This commit is contained in:
committed by
Cosmin Cojocar
parent
1c438e36af
commit
a7cff91312
25
helpers.go
25
helpers.go
@@ -256,3 +256,28 @@ func GetPkgAbsPath(pkgPath string) (string, error) {
|
||||
}
|
||||
return absPath, nil
|
||||
}
|
||||
|
||||
// ConcatString recusively concatenates strings from a binary expression
|
||||
func ConcatString(n *ast.BinaryExpr) (string, bool) {
|
||||
var s string
|
||||
// sub expressions are found in X object, Y object is always last BasicLit
|
||||
if rightOperand, ok := n.Y.(*ast.BasicLit); ok {
|
||||
if str, err := GetString(rightOperand); err == nil {
|
||||
s = str + s
|
||||
}
|
||||
} else {
|
||||
return "", false
|
||||
}
|
||||
if leftOperand, ok := n.X.(*ast.BinaryExpr); ok {
|
||||
if recursion, ok := ConcatString(leftOperand); ok {
|
||||
s = recursion + s
|
||||
}
|
||||
} else if leftOperand, ok := n.X.(*ast.BasicLit); ok {
|
||||
if str, err := GetString(leftOperand); err == nil {
|
||||
s = str + s
|
||||
}
|
||||
} else {
|
||||
return "", false
|
||||
}
|
||||
return s, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user