From 4861a980be972b8093cefbc64d9491c814c75286 Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Mon, 30 May 2022 14:37:27 +0200 Subject: [PATCH] Python: Fix cryptography modeling The old code was my own suggestion, that I thought would just work, but was also slightly skeptical about. I tested out whether it works with the code below ```codeql predicate foo(int input, string res) { input = 1 and res = "that was one" } from int input, string res where input in [1, 2] and if foo(input, res) then any() else res = "not one" select input, res ``` which gave the 3 results ``` 1 | that was one 1 | not one 2 | not one ``` only by rewriting the code to be the one below, did I get down to the 2 results I actually wanted. So I've done the same kind of rewrite in the commit. ```codeql predicate foo(int input, string res) { input = 1 and res = "that was one" } from int input, string res where input in [1, 2] and if foo(input, _) then foo(input, res) else res = "not one" select input, res ``` --- python/ql/lib/semmle/python/frameworks/Cryptography.qll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ql/lib/semmle/python/frameworks/Cryptography.qll b/python/ql/lib/semmle/python/frameworks/Cryptography.qll index 29b9c6b17e8..954def9e7da 100644 --- a/python/ql/lib/semmle/python/frameworks/Cryptography.qll +++ b/python/ql/lib/semmle/python/frameworks/Cryptography.qll @@ -195,8 +195,8 @@ private module CryptographyModel { call.getArg(0), call.getArgByName("algorithm") ] and exists(DataFlow::Node modeArg | modeArg in [call.getArg(1), call.getArgByName("mode")] | - if modeArg = modeClassRef(modeName).getReturn().getAUse() - then any() + if modeArg = modeClassRef(_).getReturn().getAUse() + then modeArg = modeClassRef(modeName).getReturn().getAUse() else modeName = "" ) )