Skip to content

Commit 279043a

Browse files
committed
[GR-12242] Disallow chdir and getcwd if no native/host access is allowed
1 parent b63a474 commit 279043a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,12 @@ public abstract static class CwdNode extends PythonBuiltinNode {
263263
@TruffleBoundary
264264
@Specialization
265265
String cwd() {
266-
// TODO(fa) that should actually be retrieved from native code
267-
return System.getProperty("user.dir");
266+
if (getContext().isExecutableAccessAllowed()) {
267+
// TODO(fa) that should actually be retrieved from native code
268+
return System.getProperty("user.dir");
269+
} else {
270+
return "";
271+
}
268272
}
269273

270274
}
@@ -275,14 +279,16 @@ public abstract static class ChdirNode extends PythonBuiltinNode {
275279
@TruffleBoundary
276280
@Specialization
277281
PNone chdir(String spath) {
278-
// TODO(fa) that should actually be set via native code
279-
try {
280-
if (Files.exists(Paths.get(spath))) {
281-
System.setProperty("user.dir", spath);
282-
return PNone.NONE;
282+
if (getContext().isExecutableAccessAllowed()) {
283+
// TODO(fa) that should actually be set via native code
284+
try {
285+
if (Files.exists(Paths.get(spath))) {
286+
System.setProperty("user.dir", spath);
287+
return PNone.NONE;
288+
}
289+
} catch (InvalidPathException e) {
290+
// fall through
283291
}
284-
} catch (InvalidPathException e) {
285-
// fall through
286292
}
287293
throw raise(PythonErrorType.FileNotFoundError, "No such file or directory: '%s'", spath);
288294
}

0 commit comments

Comments
 (0)