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

group_access_list() always adds group 'root' #44

Open
LucaFulchir opened this issue Jan 27, 2021 · 1 comment · Fixed by rustadopt/uzers-rs#1
Open

group_access_list() always adds group 'root' #44

LucaFulchir opened this issue Jan 27, 2021 · 1 comment · Fixed by rustadopt/uzers-rs#1

Comments

@LucaFulchir
Copy link

Hi, I'm kinda new at rust, but I think I have found a bug in this crate

Basically the function group_access_list should return the list the current available groups for the process
...except it seems to always add the root group

The bug might be here:

    let mut buff: Vec<gid_t> = vec![0; 1024];
[...]
    let res = unsafe {
        libc::getgroups(1024, buff.as_mut_ptr())
    };
[...]
    if res < 0 {...
    else {
        let mut groups = buff.into_iter()

The vector has 1024 elements inside, default 0. Then the libc::getgroups will get, say res = 42 groups
but buff.into_iter() goes through all 1024 elements.

The final groups.dedup_by_key(|i| i.gid()); removes multiple occurrences of the root group.
However, even that is probably kinda wrong since the docs say:

Removes all but the first of consecutive elements in the vector that resolve to the same key

...meaning that the list root,users,root will not get deduped, correct?

I have not checked for similar bugs elsewhere in the codebase

@LucaFulchir
Copy link
Author

pub fn get_user_groups seems to have the same problem:

    let res = unsafe {
        libc::getgrouplist(name.as_ptr(), gid, buff.as_mut_ptr(), &mut count)
    };

since count is a value-result ans is not used again, same thing with the dedup, too. I don't think the result of these function has much of any guarantee, so assuming that repeated groups are sequential is probably wrong

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 a pull request may close this issue.

1 participant