This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes test overwrites /dev/null
Type: Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: scotdoyle, theller
Priority: normal Keywords:

Created on 2006-07-12 18:22 by scotdoyle, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gccdevnull.txt scotdoyle, 2006-07-12 22:17 Patch for Lib/ctypes/util.py
util.diff theller, 2006-07-13 08:28 Another patch for Lib/ctypes/util.py
Messages (6)
msg29144 - (view) Author: Scot Doyle (scotdoyle) Date: 2006-07-12 18:22
Steps to reproduce on Debian Sarge:
1. ls -l /dev/null
2. wget
http://www.python.org/ftp/python/2.5/Python-2.5b2.tgz
3. tar xvzf Pyth*
4. cd Pyth*
5. ./configure
6. make
7. su
8. make test
9. ls -l /dev/null

/dev/null goes from being a special character device to
a normal file of length zero.

The following command can be used instead of step 8
above to delete /dev/null
./python -c 'import ctypes.test.test_find'


To recreate /dev/null:
1. su
2. rm /dev/null
3. mknod -m 666 /dev/null c 1 3
4. chown root:root /dev/null
msg29145 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-12 18:53
Logged In: YES 
user_id=11105

Now, that is an 'interesting' bug.  ctypes.util.find_library
does execute shell commands that happen to have '/dev/null'
in them, but it is completely unclear to me how one can
overwrite /dev/null (even if root).  Can you see anything
that's wrong there (That code is not from me, and I'm not at
all an expert in linux programming)?

BTW, I cannot reproduce this on ubuntu with 'sudo ./python
-c "import ctypes.test.test_find"'.
msg29146 - (view) Author: Scot Doyle (scotdoyle) Date: 2006-07-12 22:17
Logged In: YES 
user_id=1554504

Hey Thomas, that pointer is just what I needed :-)

/dev/null was being deleted by gcc. Discussion at
http://www.cs.helsinki.fi/linux/linux-kernel/2001-38/1503.html 

The attached patch fixed the problem on Debian Sarge and
Ubuntu 6.06.
msg29147 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-13 08:28
Logged In: YES 
user_id=11105

Scot, your patch is not correct because 'cmd' is never
executed.  However, I was able to reproduce the overwriting
of /dev/null by calling 'ctypes.util.find_library' for a
shared lib that does not exist.  Attached is a new patch
'util.diff' which fixes the problem for me.  Can you please
verify that it also works for you?

Thanks for finding the bug and locating the problem!
msg29148 - (view) Author: Scot Doyle (scotdoyle) Date: 2006-07-13 13:56
Logged In: YES 
user_id=1554504

Yes, not executing the command was one way to fix the bug :-)

Thanks for catching that. I verified the new patch to work.
msg29149 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-07-13 17:44
Logged In: YES 
user_id=11105

Thanks.  Commited as r50619.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43660
2006-07-12 18:22:15scotdoylecreate