rfc: auto_user_id implicit bug

Alexander Belchenko bialix at ukr.net
Tue Jan 30 11:34:06 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fixing auto_user_id I found implicit bug in current realization.
Here excerpt from bzrlib/config.py

def _auto_user_id():
    ...
    try:
        import pwd
	...
    except ImportError:
        import getpass
        try:
            realname = username = getpass.getuser().decode(bzrlib.user_encoding)
        except UnicodeDecodeError:
		...

This code contains implicit bug inside.
Standard pwd module is exist *only* on Unix platform.
So when import of pwd fails bzr falling down to import getpass.
But function getpass.getuser *also* try to import pwd!
Here the actual code:

def getuser():
    import os
    for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
        user = os.environ.get(name)
        if user:
            return user

    # If this fails, the exception will "explain" why
    import pwd
    return pwd.getpwuid(os.getuid())[0]

I think that right way to fix this implicit bug in bzr is
just copy-paste from getuser() iteration over env variables.

Anyway I fix auto_user_id for windows (especially win98)
in different way,
so I just want to notice about this issue because it may
affects Mac users.

Alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFvy0uzYr338mxwCURAhObAJ9vKjAJ9VUucyUIvBP+ASsPyWMzyACfTRUf
Nfsah3gpi2rny38TLWdoVmY=
=vOih
-----END PGP SIGNATURE-----




More information about the bazaar mailing list