Python: Model new `binascii` codecs · github/codeql@3272fd5 · GitHub
Skip to content

Commit 3272fd5

Browse files
committed
Python: Model new binascii codecs
Adds models for various kinds of codecs introduced in Python 3.15. See the change note for more details.
1 parent 74211cc commit 3272fd5

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions

‎python/ql/lib/semmle/python/frameworks/Stdlib.qll‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,59 @@ module StdlibPrivate {
17601760
}
17611761
}
17621762

1763+
// ---------------------------------------------------------------------------
1764+
// binascii
1765+
// ---------------------------------------------------------------------------
1766+
/** A call to a supported encoding function in the `binascii` module. */
1767+
private class BinasciiEncodeCall extends Encoding::Range, DataFlow::CallCfgNode {
1768+
string codec;
1769+
1770+
BinasciiEncodeCall() {
1771+
codec in ["base32", "base85", "ascii85"] and
1772+
this = API::moduleImport("binascii").getMember("b2a_" + codec).getACall()
1773+
}
1774+
1775+
override DataFlow::Node getAnInput() {
1776+
result = this.getArg(0)
1777+
or
1778+
codec in ["base32", "base85"] and
1779+
result = this.getArgByName("alphabet")
1780+
}
1781+
1782+
override DataFlow::Node getOutput() { result = this }
1783+
1784+
override string getFormat() {
1785+
result in ["Base32", "Base85", "Ascii85"] and
1786+
result.toLowerCase() = codec
1787+
}
1788+
}
1789+
1790+
/** A call to a supported decoding function in the `binascii` module. */
1791+
private class BinasciiDecodeCall extends Decoding::Range, DataFlow::CallCfgNode {
1792+
string codec;
1793+
1794+
BinasciiDecodeCall() {
1795+
codec in ["base32", "base85", "ascii85"] and
1796+
this = API::moduleImport("binascii").getMember("a2b_" + codec).getACall()
1797+
}
1798+
1799+
override predicate mayExecuteInput() { none() }
1800+
1801+
override DataFlow::Node getAnInput() {
1802+
result = this.getArg(0)
1803+
or
1804+
codec in ["base32", "base85"] and
1805+
result = this.getArgByName("alphabet")
1806+
}
1807+
1808+
override DataFlow::Node getOutput() { result = this }
1809+
1810+
override string getFormat() {
1811+
result in ["Base32", "Base85", "Ascii85"] and
1812+
result.toLowerCase() = codec
1813+
}
1814+
}
1815+
17631816
// ---------------------------------------------------------------------------
17641817
// json
17651818
// ---------------------------------------------------------------------------
Lines changed: 72 additions & 0 deletions

0 commit comments

Comments
 (0)