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.

Title: ctypes test overwrites /dev/null
Type: Stage:
Components: Extension Modules Versions: Python 2.5
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.

File name Uploaded Description Edit
gccdevnull.txt scotdoyle, 2006-07-12 22:17 Patch for Lib/ctypes/
util.diff theller, 2006-07-13 08:28 Another patch for Lib/ctypes/
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
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 

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 

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

/dev/null was being deleted by gcc. Discussion at 

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 

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 

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 

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