Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch TypeError for int(None) (RhBug:1597005) #1428

Closed
wants to merge 1 commit into from

Conversation

j-mracek
Copy link
Contributor

In some cases "/proc/self/loginuid" could be not present, therefore it
contains None. The conversion to int returns not a ValueError but
TypeError.

https://bugzilla.redhat.com/show_bug.cgi?id=1597005

In some cases "/proc/self/loginuid" could be not present, therefore it
contains None. The conversion to int returns not a ValueError but
TypeError.

https://bugzilla.redhat.com/show_bug.cgi?id=1597005
@@ -373,7 +373,7 @@ def _getloginuid():
with open("/proc/self/loginuid") as fo:
data = fo.read()
return int(data)
except (IOError, ValueError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is correct. When you try to open non-existent file, Python will raise IOError (or its more specific subclass FileNotFoundError in the case of python3). So the int(data) line is never executed.

I downloaded and run in qemu the risc image mentioned in the bz and found this:

# rpm -q dnf
dnf-2.7.5-8.fc28.noarch

# grep -A11 'def _getloginuid' /usr/lib/python3.6/site-packages/dnf/yum/misc.py 
def _getloginuid():
    """ Get the audit-uid/login-uid, if available. None is returned if there
        was a problem. Note that no caching is done here. """
    #  We might normally call audit.audit_getloginuid(), except that requires
    # importing all of the audit module. And it doesn't work anyway: BZ 518721
    try:
        with open("/proc/self/loginuid") as fo:
            data = fo.read()
            return int(data)
    except (IOError, ValueError):
        return None

The version of dnf used on risc is too old and is missing the fallback to os.getuid() introduced by commit 70779df

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for comment. Good point.

@j-mracek j-mracek closed this Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants