[issue17180] shutil copy* unsafe on POSIX - they preserve setuid/setgit bits

2013-02-11 Thread Milko Krachounov
New submission from Milko Krachounov: When copying the mode of a file with copy, copy2, copymode, copystat or copytree, all permission bits are copied (including setuid and setgit), but the owner of the file is not. This can be used for privilege escalation. An example: -rwSr--r-- 1 milko

[issue8604] Adding an atomic FS write API

2011-05-13 Thread Milko Krachounov
Milko Krachounov added the comment: > Something's missing in all the implementations presented: > to make sure that the new version of the file is available afer > a crash, fsync must be called on the containing directory after > the rename. I upgraded my proposed approa

[issue8604] Adding an atomic FS write API

2011-05-12 Thread Milko Krachounov
Milko Krachounov added the comment: Well, since I had a typo in the main method which called the Windows implementation on POSIX, the unit test works on the code for Windows when ran on POSIX. Heh, I'm sorry for the noise, but it seems that re-reading the code four times and running the

[issue8604] Adding an atomic FS write API

2011-05-12 Thread Milko Krachounov
Milko Krachounov added the comment: I have a class for overwriting files "properly" that I use in three of my projects. It aims to be atomic as possible, supports creating backups, but it doesn't have functions to set or retain permissions when requested (which might be desi

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-12 Thread Milko Krachounov
Milko Krachounov added the comment: > For the Python implementation, the GIL is not enough to > ensure the atomicity of a process creation. That's why > _posixsubprocess was created. I suppose that other parts > of subprocess are not atomic and a lock is required to > ensu

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20013/subprocess-cloexec-atomic-py3k-tests2-close_fds.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20009/subprocess-cloexec-atomic-py3k-tests1.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20005/subprocess-cloexec-atomic-py3k.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20020/subprocess-02-cloexec_tests.patch ___ Python tracker <http://bugs.python.org/issue7213> ___ ___

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20019/subprocess-02-cloexec_tests.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20019/subprocess-02-cloexec_tests.patch ___ Python tracker <http://bugs.python.org/issue7213> ___ ___

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20018/subprocess-01-atomic_cloexec_pipe2.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] subprocess leaks open file descriptors between Popen instances causing hangs

2010-12-11 Thread Milko Krachounov
Milko Krachounov added the comment: OK, I have created new updated patches. I haven't combined them in one patch because some of the changes can be applied independently, the three patches can be cat'ed together if anyone sees separate patches a problem. ;) I. Changes: * Now pipe

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Milko Krachounov added the comment: I add a patch that tests close_fds (there's no test for close_fds), that requires the tests1 patch. By the way, should there be a test for the atomicity of the operations? -- Added file: http://bugs.python.org/file20013/subprocess-cloexec-a

[issue6559] [PATCH]add pass_fds paramter to subprocess.Popen()

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20012/subprocess-pass_fd_fix_example.patch ___ Python tracker <http://bugs.python.org/issue6

[issue6559] [PATCH]add pass_fds paramter to subprocess.Popen()

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20011/test_pass_fds.py ___ Python tracker <http://bugs.python.org/issue6559> ___ ___ Python-bug

[issue6559] [PATCH]add pass_fds paramter to subprocess.Popen()

2010-12-11 Thread Milko Krachounov
Milko Krachounov added the comment: The patch doesn't seem to work. I added this before closerange in _close_all_but_a_sorted_few_fds: print("Closing", start_fd, "up to", fd, "exclusive") And used the attached script to run as a subprocess to check for o

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20009/subprocess-cloexec-atomic-py3k-tests1.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20008/subprocess-cloexec-atomic-py3k-tests1.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file20008/subprocess-cloexec-atomic-py3k-tests1.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file20007/subprocess-cloexec-atomic-py3k-tests1.patch ___ Python tracker <http://bugs.python.org/issue7

[issue7213] Popen.subprocess change close_fds default to True

2010-12-11 Thread Milko Krachounov
Milko Krachounov added the comment: I attached unit tests that test that cloexec is properly set. I can't test my tests too well with the unpatched version because runtests.sh is too complicated to use, and doesn't print any useful output by default. -- Added f

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Milko Krachounov added the comment: I created another patch that attempts to create the pipes atomically. On GNU/Linux, if pipe2 is available, it uses it to create the pipes, and there is no race. On other POSIX platforms, pipe and fcntl are called without releasing the GIL - relying on the

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Milko Krachounov added the comment: It's almost exactly the same race condition as the one described in issue 2320. The pipes are created and stay without the CLOEXEC flag for a while (until the process has been forked and fcntl has been called). During that time another thread can lau

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Milko Krachounov added the comment: > I'm +1 on it, but I think it should be the default; instead, > your proposed patch adds a new argument to the public API. Why do you > think it's necessary to do so? I don't think it's necessary. I put it there because whe

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Changes by Milko Krachounov : Removed file: http://bugs.python.org/file1/subprocess-cloexec-py3k.patch ___ Python tracker <http://bugs.python.org/issue7213> ___ ___

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Milko Krachounov added the comment: The cloexec approach still doesn't help with issue 2320. In fact, with threading and people calling subprocess from multiple threads, *this* issue wouldn't be fixed with my patch either unless mutexes are used. It's impossible to avoid a

[issue7213] Popen.subprocess change close_fds default to True

2010-12-10 Thread Milko Krachounov
Milko Krachounov added the comment: I'd offer two ideas. 1. Add a constant DISREGARD_FDS to the subprocess module could help. It would allow the user to specify his intent, and let the implementation choose the best action. Popen(..., close_fds=subprocess.DISREGARD_FDS) would mean tha

[issue10549] help(cls1) breaks when cls1 has staticmethod(cls2) attribute

2010-11-27 Thread Milko Krachounov
New submission from Milko Krachounov : If I make a class B, and add staticmethod(A) as an attribute when B is another class, help(B) breaks. The issue appears with Python 2.6.6, trunk, 3.1.3c1, and py3k SVN. Python 2.7 (trunk:86836, Nov 27 2010, 18:23:07) [GCC 4.4.5] on linux2 Type "

[issue6472] Inconsistent use of "iterator" in ElementTree doc & diff between Py and C modules

2009-12-05 Thread Milko Krachounov
Milko Krachounov added the comment: This isn't just a documentation issue. A function named getiterator(), for which the docs say that it returns an iterator, should return an iterator, not just an iterable. They have different semantics and can't be used interchangeably, so the be

[issue4356] Add "key" argument to "bisect" module functions

2009-11-02 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file15250/bench_bisect_key.py ___ Python tracker <http://bugs.python.org/issue4356> ___ ___ Python-bug

[issue4356] Add "key" argument to "bisect" module functions

2009-11-02 Thread Milko Krachounov
Changes by Milko Krachounov : Added file: http://bugs.python.org/file15249/bisect-py3k.patch ___ Python tracker <http://bugs.python.org/issue4356> ___ ___ Python-bug

[issue4356] Add "key" argument to "bisect" module functions

2009-11-02 Thread Milko Krachounov
Milko Krachounov added the comment: I've been bugged by the lack of key= argument for bisect for some time now, and today I got to read this and the previous issues about the matter. I still fail to understand the reasons for the rejections. It might encourage bad design in which expensiv

[issue7213] Popen.subprocess change close_fds default to True

2009-10-26 Thread Milko Krachounov
New submission from Milko Krachounov : Currently, close_fds defaults to False. The are few cases in which one would want to leave the fds open, in all the rest leaving them open can lead to unpleasant side effects. For example, the following doesn't work: >>> p1 = Popen([

[issue7006] The replacement suggested for callable(x) in py3k is not equivalent

2009-09-27 Thread Milko Krachounov
Milko Krachounov added the comment: My suggestion is not only unreadable, but wrong. It's even less accurate than hasattr(x, '__call__'), as it doesn't look in all the classes in the MRO. Using isinstance(x, collections.Callable) should probably be the correct replacement fo

[issue7006] The replacement suggested for callable(x) in py3k is not equivalent

2009-09-27 Thread Milko Krachounov
New submission from Milko Krachounov : hasattr(x, '__call__') has been suggested as a replacement for callable(x) in the documentation and in the warning when running python2.6 with -3. It is also what 2to3 replaces it with. However, the two are not equivalent. 1. I can add a __call__

[issue6973] subprocess.Popen.send_signal doesn't check whether the process has terminated

2009-09-22 Thread Milko Krachounov
New submission from Milko Krachounov : When subprocess.Popen.send_signal is called, it simply calls os.kill(self.pid, ...) without checking whether the child has already terminated. If the child has been terminated, and Popen.wait() or Popen.poll() have been called, a process with PID self.pid