Subject: misc/24381: Strange definitions of UID_MAX/GID_MAX and comments
To: None <>
From: Christian Biere <>
List: netbsd-bugs
Date: 02/10/2004 17:04:03
>Number:         24381
>Category:       misc
>Synopsis:       Strange definitions of UID_MAX/GID_MAX and comments
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 10 17:05:00 UTC 2004
>Originator:     Christian Biere
>Release:        NetBSD 1.6ZH
System: NetBSD cyclonus 1.6ZH NetBSD 1.6ZH (STARSCREAM) #0: Fri Feb 6 00:16:58 CET 2004 root@cyclonus:/usr/src/sys/arch/i386/compile/STARSCREAM i386

#define GID_MAX            2147483647U  /* max value for a gid_t (2^31-2) */
#define UID_MAX            2147483647U  /* max value for a uid_t (2^31-2) */

2147483647U is actually 2^31-1, not 2^31-2. This was already noticed by
Geoff Wing back in 1999:

Note the original commit message by Luke Mewburn:
Revision 1.14, Thu May 22 03:02:50 1997 UTC (6 years, 8 months ago) by lukem
Branch: MAIN
Changes since 1.13: +3 -1 lines

define GID_MAX (max value permitted in gid_t) and UID_MAX (ditto for uid_t)
to 2^32-2

Both were defined to 4294967294 as claimed in this message.

Here's his following commit message:
Change {UID,GID}_MAX from 2^32-2 to 2^31-2 (which was the original
intention). This is because setreuid takes signed ints, which may
be -1 to indicate ``don't change [ug]id''.

There are two mistakes. (-1) is 2^32-1 as long as we're at talking about
uint32_t (which is what uid_t and gid_t effectively are) but never 2^31-2.
I cannot see where setreuid uses signed ints, either. It never did, CMIIW.
The only reserved value (internally) is (-1) which is (2^32)-1
(sys/kern/kern_prot.c). So the intial commit was correct and the next was
caused by a misconception.


Correct at least the comments to reflect reality and correct the values as
well if there aren't any obstacles.