Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: follow_symlinks
Changeset: r83687:a60a494657a8
Date: 2016-04-15 16:42 +0100
http://bitbucket.org/pypy/pypy/changeset/a60a494657a8/

Log:    Corner case: don't crash if path == -1

diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -178,13 +178,17 @@
 @specialize.arg(2)
 def unwrap_fd(space, w_value, allowed_types='integer'):
     try:
-        return space.c_int_w(w_value)
+        result = space.c_int_w(w_value)
     except OperationError as e:
         if not e.match(space, space.w_OverflowError):
             raise oefmt(space.w_TypeError,
                 "argument should be %s, not %T", allowed_types, w_value)
         else:
             raise
+    if result == -1:
+        # -1 is used as sentinel value for not a fd
+        raise oefmt(space.w_ValueError, "invalid file descriptor: -1")
+    return result
 
 def _unwrap_dirfd(space, w_value):
     if space.is_none(w_value):
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -193,6 +193,7 @@
         assert "can't specify None" in str(excinfo.value)
         excinfo = raises(TypeError, self.posix.stat, 2.)
         assert "should be string, bytes or integer, not float" in 
str(excinfo.value)
+        raises(ValueError, self.posix.stat, -1)
 
     if hasattr(__import__(os.name), "statvfs"):
         def test_statvfs(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to