Python "import comtypes.client" calls pwd.py indirectly -
i have not deep experience in python. working on last application found interesting thing. put script name pwd.py in same directory main script. created pwd.py test basic modules , methods, no more purpose.
but surprised later found main script indirectly calls pwd.py! put debug printouts , found import statement "import comtypes.client" calls pwd.py.
well...i thought standard feature don't know still, but:
recursive search in python_home (c:\python343 in case) not show pwd.py in standard python directories. tried recursive search file content inside c:\python343 find calls pwd.py, search returned nothing (i used total commander search ctrl+f7, fails sometimes).
google says nothing well-known regarding pwd.py
so, feature , why not described anywhere? kind of vulnerability. 1 can create pwd.py in same directory main script located , put code inside pwd.py...
may check behavior on own system? if works so, can find description of feature?
i found line "import comtypes.client" causes "issue". here content of main script:
#!c:\python343\python import comtypes.client # line causes pwd.py called indirectly !!! and here content of pwd.py put same directory:
#!c:\python343\python print('pwd.py called!') raise runtimeerror("we got here!") # put exception kevin asked me above, not sure python knows "throw" (it not work me) use "raise" after got following result:
c:\dev>test.py pwd.py called! traceback (most recent call last): file "c:\dev\test.py", line 2, in <module> import comtypes.client # line causes pwd.py called indirectly !!! file "c:\python343\lib\site-packages\comtypes\client\__init__.py", line 31, in <module> comtypes.client._code_cache import _find_gen_dir file "c:\python343\lib\site-packages\comtypes\client\_code_cache.py", line 7, in <module> import ctypes, logging, os, sys, tempfile, types file "c:\python343\lib\tempfile.py", line 34, in <module> import shutil _shutil file "c:\python343\lib\shutil.py", line 24, in <module> pwd import getpwnam file "c:\dev\pwd.py", line 3, in <module> raise runtimeerror("we got here!") runtimeerror: got here! so call chain is:
c:\dev\test.py c:\python343\lib\site-packages\comtypes\client\__init__.py c:\python343\lib\site-packages\comtypes\client\_code_cache.py c:\python343\lib\tempfile.py c:\python343\lib\shutil.py c:\dev\pwd.py and line "from pwd import getpwnam" seems responsible call of pwd.py. after changed main script following way:
#!c:\python343\python import pwd # know it's you! and really, calls pwd.py! kevin simple idea. remaining question is correct "import pwd" calls pwd.py same directory? interesting feature :-)
Comments
Post a Comment