Skip to content

Commit 6260067

Browse files
committed
raise OSError properly when trying to make a socket inheritable
1 parent 66805f8 commit 6260067

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import com.oracle.graal.python.builtins.objects.ints.PInt;
114114
import com.oracle.graal.python.builtins.objects.list.PList;
115115
import com.oracle.graal.python.builtins.objects.module.PythonModule;
116+
import com.oracle.graal.python.builtins.objects.socket.PSocket;
116117
import com.oracle.graal.python.builtins.objects.str.PString;
117118
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
118119
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
@@ -509,15 +510,10 @@ Object setInheritableStd(@SuppressWarnings("unused") int fd, @SuppressWarnings("
509510
}
510511

511512
@Specialization(guards = "fd > 2")
512-
Object setInheritable(int fd, @SuppressWarnings("unused") Object inheritable) {
513-
try {
514-
String path = getResources().getFilePath(fd);
515-
TruffleFile f = getContext().getEnv().getTruffleFile(path);
516-
if (!f.exists()) {
517-
throw raise(OSError, "No such file or directory: '%s'", path);
518-
}
519-
} catch (NullPointerException e) {
520-
throw raise(OSError, "Not a valid file descriptor, maybe a socket?'");
513+
Object setInheritable(VirtualFrame frame, int fd, @SuppressWarnings("unused") Object inheritable) {
514+
Channel ch = getResources().getFileChannel(fd);
515+
if (ch == null || ch instanceof PSocket) {
516+
throw raiseOSError(frame, OSErrorEnum.EBADF.getNumber());
521517
}
522518
// TODO: investigate how to map this to the truffle file api (if supported)
523519
return PNone.NONE;

0 commit comments

Comments
 (0)