Skip to content

Commit 05b0daa

Browse files
committed
Add the test of shutil module in FileSystemAccess.py
1 parent fed1d88 commit 05b0daa

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,19 +2993,12 @@ private module StdlibPrivate {
29932993
}
29942994
}
29952995

2996-
/**
2997-
* A call to the `shutil.copyfileobj` function.
2998-
*
2999-
* See https://docs.python.org/3/library/shutil.html#shutil.copyfileobj
3000-
*/
2996+
// TODO: once we have flow summaries, model `shutil.copyfileobj` which copies the content between its' file-like arguments.
2997+
// See https://docs.python.org/3/library/shutil.html#shutil.copyfileobj
30012998
private class ShutilCopyfileobjCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
30022999
ShutilCopyfileobjCall() { this = shutil().getMember("copyfileobj").getACall() }
30033000

3004-
override DataFlow::Node getAPathArgument() {
3005-
result in [
3006-
this.getArg(0), this.getArgByName("fsrc"), this.getArg(1), this.getArgByName("fdst")
3007-
]
3008-
}
3001+
override DataFlow::Node getAPathArgument() { none() }
30093002
}
30103003

30113004
/**

python/ql/test/library-tests/frameworks/stdlib/FileSystemAccess.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import stat
55
import tempfile
6+
import shutil
67

78
open("file") # $ getAPathArgument="file"
89
open(file="file") # $ getAPathArgument="file"
@@ -238,3 +239,30 @@ def test_fspath():
238239

239240
tempfile.TemporaryDirectory("suffix", "prefix", "dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
240241
tempfile.TemporaryDirectory(suffix="suffix", prefix="prefix", dir="dir") # $ getAPathArgument="suffix" getAPathArgument="prefix" getAPathArgument="dir"
242+
243+
shutil.rmtree("path") # $ getAPathArgument="path"
244+
shutil.rmtree(path="path") # $ getAPathArgument="path"
245+
246+
shutil.copyfile("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
247+
shutil.copyfile(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
248+
249+
shutil.copy("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
250+
shutil.copy(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
251+
252+
shutil.copy2("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
253+
shutil.copy2(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
254+
255+
shutil.copytree("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
256+
shutil.copytree(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
257+
258+
shutil.move("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
259+
shutil.move(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
260+
261+
shutil.copymode("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
262+
shutil.copymode(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
263+
264+
shutil.copystat("src", "dst") # $ getAPathArgument="src" getAPathArgument="dst"
265+
shutil.copystat(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
266+
267+
shutil.disk_usage("path") # $ getAPathArgument="path"
268+
shutil.disk_usage(path="path") # $ getAPathArgument="path"

0 commit comments

Comments
 (0)