Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2511,12 +2511,10 @@ int main (int argc, char **argv)
subgid_count = getdef_ulong ("SUB_GID_COUNT", 65536);
is_sub_uid = want_subuid_file () &&
subuid_count > 0 && sub_uid_file_present () &&
(!rflg || Fflg) &&
(!user_id || (user_id <= uid_max && user_id >= uid_min));
(!rflg && (!user_id || (user_id <= uid_max && user_id >= uid_min))) || Fflg;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems brittle. It is affected by the fact that && has more precedence than ||, which is something not well known.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I'm more a Python person, I can mostly read C code but not really write it.
Doesn't the parenthesis group the tests so there is not && and || in the same test ?

(
  !rflg && (
    !user_id || (
      user_id <= uid_max &&  user_id >= uid_min
    )
  )
) || Fflg;

Copy link
Collaborator

@alejandro-colomar alejandro-colomar Jan 18, 2026

Choose a reason for hiding this comment

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

Yes, but you have the full expression (see lines 2513 and above) as

a && b && && c && (...) || e

Those && and || don't necessarily interact as you'd expect.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but you have the full expression (see lines 2513 and above) as

a && b && && c && (...) || e

Those && and || don't necessarily interact as you'd expect.

Ah yes I see, well I'm out of my depth on that.
I will see if I can either "prove" this work or fix it.

And also, thanks for your help !

is_sub_gid = want_subgid_file() &&
subgid_count > 0 && sub_gid_file_present() &&
(!rflg || Fflg) &&
(!user_id || (user_id <= uid_max && user_id >= uid_min));
(!rflg && (!user_id || (user_id <= uid_max && user_id >= uid_min))) || Fflg;
#endif /* ENABLE_SUBIDS */

if (run_parts ("/etc/shadow-maint/useradd-pre.d", user_name,
Expand Down
Loading