File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
go/ql/src/experimental/CWE-321 Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,26 @@ module HardcodedKeys {
188188 }
189189 }
190190
191+ /**
192+ * Marks anything returned alongside an error-value that is known
193+ * to be non-nil by virtue of a guarding check as harmless.
194+ *
195+ * For example, `if err != nil { return "", err }` is unlikely to be
196+ * contributing a dangerous hardcoded key.
197+ */
198+ private class ReturnedAlongsideErrorSanitizerGuard extends Sanitizer {
199+
200+ ReturnedAlongsideErrorSanitizerGuard ( ) {
201+ exists ( ControlFlow:: ConditionGuardNode guard , SsaWithFields errorVar , ReturnStmt r |
202+ guard .ensuresNeq ( errorVar .getAUse ( ) , Builtin:: nil ( ) .getARead ( ) ) and
203+ guard .dominates ( this .getBasicBlock ( ) ) and
204+ r .getExpr ( 1 ) = errorVar .getAUse ( ) .asExpr ( ) and
205+ this .asExpr ( ) = r .getExpr ( 0 )
206+ )
207+ }
208+
209+ }
210+
191211 /** Mark any formatting string call as a sanitizer */
192212 private class FormattingSanitizer extends Sanitizer {
193213 FormattingSanitizer ( ) { exists ( Formatting:: StringFormatCall s | s .getAResult ( ) = this ) }
You can’t perform that action at this time.
0 commit comments