FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/analysis/ImportFailure.ql at codeql-cli/v2.15.4 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
997
Pull requests
454
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
ql
/
src
/
analysis
/
ImportFailure.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (74 loc) · 2.42 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
analysis
/
ImportFailure.ql
Copy path
File metadata and controls
83 lines (74 loc) · 2.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @name Unresolved import
* @description An unresolved import may result in reduced coverage and accuracy of analysis.
* @kind problem
* @problem.severity info
* @id py/import-failure
*/
import
python
ImportExpr
alternative_import
(
ImportExpr
ie
)
{
exists
(
Alias
thisalias
,
Alias
otheralias
|
(
thisalias
.
getValue
(
)
=
ie
or
thisalias
.
getValue
(
)
.
(
ImportMember
)
.
getModule
(
)
=
ie
)
and
(
otheralias
.
getValue
(
)
=
result
or
otheralias
.
getValue
(
)
.
(
ImportMember
)
.
getModule
(
)
=
result
)
and
(
exists
(
If
i
|
i
.
getBody
(
)
.
contains
(
ie
)
and
i
.
getOrelse
(
)
.
contains
(
result
)
)
or
exists
(
If
i
|
i
.
getBody
(
)
.
contains
(
result
)
and
i
.
getOrelse
(
)
.
contains
(
ie
)
)
or
exists
(
Try
t
|
t
.
getBody
(
)
.
contains
(
ie
)
and
t
.
getAHandler
(
)
.
contains
(
result
)
)
or
exists
(
Try
t
|
t
.
getBody
(
)
.
contains
(
result
)
and
t
.
getAHandler
(
)
.
contains
(
ie
)
)
)
)
}
string
os_specific_import
(
ImportExpr
ie
)
{
exists
(
string
name
|
name
=
ie
.
getImportedModuleName
(
)
|
name
.
matches
(
"org.python.%"
)
and
result
=
"java"
or
name
.
matches
(
"java.%"
)
and
result
=
"java"
or
name
.
matches
(
"Carbon.%"
)
and
result
=
"darwin"
or
result
=
"win32"
and
(
name
=
"_winapi"
or
name
=
"_win32api"
or
name
=
"_winreg"
or
name
=
"nt"
or
name
.
matches
(
"win32%"
)
or
name
=
"ntpath"
)
or
result
=
"linux2"
and
(
name
=
"posix"
or
name
=
"posixpath"
)
or
result
=
"unsupported"
and
(
name
=
"__pypy__"
or
name
=
"ce"
or
name
.
matches
(
"riscos%"
)
)
)
}
string
get_os
(
)
{
py_flags_versioned
(
"sys.platform"
,
result
,
major_version
(
)
.
toString
(
)
)
}
predicate
ok_to_fail
(
ImportExpr
ie
)
{
alternative_import
(
ie
)
.
refersTo
(
_
)
or
os_specific_import
(
ie
)
!=
get_os
(
)
}
class
VersionTest
extends
ControlFlowNode
{
VersionTest
(
)
{
exists
(
string
name
|
name
.
matches
(
"%version%"
)
and
this
.
(
CompareNode
)
.
getAChild
+
(
)
.
pointsTo
(
Module
::
named
(
"sys"
)
.
attr
(
name
)
)
)
}
override
string
toString
(
)
{
result
=
"VersionTest"
}
}
/** A guard on the version of the Python interpreter */
class
VersionGuard
extends
ConditionBlock
{
VersionGuard
(
)
{
this
.
getLastNode
(
)
instanceof
VersionTest
}
}
from
ImportExpr
ie
where
not
ie
.
refersTo
(
_
)
and
exists
(
Context
c
|
c
.
appliesTo
(
ie
.
getAFlowNode
(
)
)
)
and
not
ok_to_fail
(
ie
)
and
not
exists
(
VersionGuard
guard
|
guard
.
controls
(
ie
.
getAFlowNode
(
)
.
getBasicBlock
(
)
,
_
)
)
select
ie
,
"Unable to resolve import of '"
+
ie
.
getImportedModuleName
(
)
+
"'."
Back
|
FazBrowse Home
|
New Git URL