[issue25481] PermissionError in subprocess.check_output() when running as a different user (not login shell)

2015-10-26 Thread jaystrict

New submission from jaystrict:

When running subprocess.check_output(['doesnotexist']) as another user, I 
expect a FileNotFoundError, but a PermissionError is thrown.

How to reproduce:

[user1 tmp]$ su --login user2
Password: 
[user2 ~]$ python
Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_output(['asdf'])
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.5/subprocess.py", line 629, in check_output
**kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1540, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'asdf'
>>> quit()
[user2 ~]$ exit
logout
[user1 tmp]$ su user2
Password: 
[user2 tmp]$ python
Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_output(['asdf'])
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.5/subprocess.py", line 629, in check_output
**kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1540, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
>>> quit()
[user2 tmp]$

--
messages: 253462
nosy: jaystrict
priority: normal
severity: normal
status: open
title: PermissionError in subprocess.check_output() when running as a different 
user (not login shell)
type: behavior
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue25481>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25481] PermissionError in subprocess.check_output() when running as a different user (not login shell)

2015-10-26 Thread jaystrict

jaystrict added the comment:

user2 in fact has permissions in the CWD.
The CWD has been set to /tmp intentionally, exactly for that reason that every 
user has "rwx" access there.

--
status: pending -> open

___
Python tracker 
<http://bugs.python.org/issue25481>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25481] PermissionError in subprocess.check_output() when running as a different user (not login shell)

2015-10-26 Thread jaystrict

jaystrict added the comment:

I just tried the same thing in /home/user2 which is the home of user2 and in /.
In both directories the result is the PermissionError. So the cause is not the 
CWD.

--

___
Python tracker 
<http://bugs.python.org/issue25481>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25481] PermissionError in subprocess.check_output() when running as a different user (not login shell)

2015-10-26 Thread jaystrict

jaystrict added the comment:

I just found that a "chmod o+x /home/user1" fixes the problem in the sense that 
now a FileNotFoundError is thrown.
So I am very certain that you can reproduce this by making your home directory 
non-executable.

Could it be that python tries to access the "original" home directory somehow? 
For example to write to a pipe?

--

___
Python tracker 
<http://bugs.python.org/issue25481>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25481] PermissionError in subprocess.check_output() when running as a different user (not login shell)

2015-10-26 Thread jaystrict

jaystrict added the comment:

Narrowing it down further:

In $PATH there is a subdirectory of /home/user1.
PATH="/home/user1/bin:/usr/local/sbin:/usr/local/bin:/usr/bin"

Doing an strace on the example above shows the line
stat("/home/user1/bin/python", 0x7fff9d365bb0) = -1 EACCES (Permission denied)
AFAICT this line is generated when the shell looks for the correct python 
executable, but it should not interfere with the (later) call to 
subprocess.check_output().

If I delete "/home/user1/bin" from $PATH, then the correct FileNotFoundError is 
thrown.

So it seems (just guessing) that subprocess.check_output() somehow throws the 
older, obsolete error code. Would this be possible?

--

___
Python tracker 
<http://bugs.python.org/issue25481>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com