MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / isTautology

Method isTautology

pkg/sql/security/scanner.go:780–814  ·  view source on GitHub ↗

isTautology checks if an expression is always true.

(expr *ast.BinaryExpression)

Source from the content-addressed store, hash-verified

778
779// isTautology checks if an expression is always true.
780func (s *Scanner) isTautology(expr *ast.BinaryExpression) bool {
781 if expr == nil {
782 return false
783 }
784
785 op := strings.ToUpper(expr.Operator)
786 if op != "=" && op != "==" {
787 return false
788 }
789
790 // Check for LiteralValue tautologies: 1=1, 2=2, 'a'='a', etc.
791 leftLit, leftIsLit := expr.Left.(*ast.LiteralValue)
792 rightLit, rightIsLit := expr.Right.(*ast.LiteralValue)
793
794 if leftIsLit && rightIsLit {
795 // Same literal values
796 leftVal := fmt.Sprintf("%v", leftLit.Value)
797 rightVal := fmt.Sprintf("%v", rightLit.Value)
798 if leftVal == rightVal {
799 return true
800 }
801 }
802
803 // Check for identifier tautologies: col=col
804 leftIdent, leftIsIdent := expr.Left.(*ast.Identifier)
805 rightIdent, rightIsIdent := expr.Right.(*ast.Identifier)
806
807 if leftIsIdent && rightIsIdent {
808 if leftIdent.Name == rightIdent.Name {
809 return true
810 }
811 }
812
813 return false
814}
815
816// checkOrInjection checks for OR-based injection patterns.
817func (s *Scanner) checkOrInjection(expr *ast.BinaryExpression, result *ScanResult) {

Callers 2

scanBinaryExpressionMethod · 0.95
checkOrInjectionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected