OpenSolaris

You are not signed in. Sign in or register.

Heads-up: henceforth uid_t and gid_t are unsigned.

Date: Fri, 25 May 2007 14:42:45 +0200
From: Casper.Dik at sun dot com
To: on-all at eng dot sun dot com, onnv-gate at onnv dot eng dot sun dot com
Subject: Heads-up: henceforth uid_t and gid_t are unsigned.


With the putback of PSARC 2007/064 related change of the
type of uid_t and gid_t from "long" (32 bit binaries) and
"int" (64 bit binaries) to "uint32_t" for both 32 and 64 bit binaries,
developers should note the following:


- There are no impacts on existing binaries, i.e., those binaries
  compiled with the old definitions.  Code does not need to be recompiled.

- When code is recompiled, standard development practices should
  catch the problems which are caused by changing the type of uid_t
  and gid_t.

  The following program demonstrates some of the problem areas:


     1	#include <unistd.h>
     2	#include <stdlib.h>
     3	#include <stdio.h>
     4	
     5	int
     6	main(void)
     7	{
     8		uid_t negone = -1;
     9	
    10		if (getuid() < 0)
    11			exit(1);
    12		
    13		(void) setreuid(negone, getuid());
    14	
    15		(void) printf("%ld\n", getuid());
    16	
    17		return (0);
    18	}

warning generated by Sun's Studio 11 compiler:


"uid.c", line 8: warning: initializer does not fit or is out of range: -1

warnings generated by Studio 11 lint:

(8) warning: constant truncated by assignment
(8) warning: initializer will be sign-extended: -1
(10) warning: suspicious comparison of unsigned with 0: op "<"

function argument ( number ) type inconsistent with format
    printf (arg 2)      unsigned int  :: (format) long  uid.c(15)

and warnings generated by gcc -Wall -Wextra:
uid.c:10: warning: comparison of unsigned expression < 0 is always false
uid.c:15: warning: long int format, uid_t arg (arg 2)

(Note that the gcc warning do not happen unless gcc's private copy
of the include file <sys/types.h> is updated, e.g., by reinstalling
the gcc package after bfu'ing; your next fresh install or upgrade
with take care of that)

Unsigned uid_t and gid_t are common on other platforms (Linux, AIX, SunOS 4)
so few or no issues in the way of opensource compability are expected.

Casper Dik