[Libguestfs] [PATCH nbdkit v2 1/3] server: Add new APIs for reading the client’s SO_PEERCRED.

Eric Blake eblake at redhat.com
Mon Oct 5 15:00:10 UTC 2020


On 10/5/20 9:04 AM, Richard W.M. Jones wrote:

>> IIUC, gid_t/uid_t don't have their signed-ness specified by POSIX,
>> nor size, but you're required to cast negative values eg
>>
>>     gid_t foo = (gid_t)-1;
>>
>> based on this, libvirt chose to expose them as "unsigned long long" to
>> maximise future proofing.
> 
> We need an in-band error indication.  I wonder if there are systems
> with valid UID or GID == (uint64_t)-1 ?

No. POSIX chown() ensures that that ([ug]id_t)(-1) can only be used as
markers, never as valid ids.  Thus they are always safe for in-band
error indication.  But Dan is correct that because it is unspecified if
[ug]id_t is signed or unsigned, and also unspecified whether they are
16-, 32-, or 64-bit quantities, makes it mandatory to write the cast
(that is, you HAVE to use ((uid_t)(-1)) instead of assuming that -1 will
promote to the correct type).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20201005/d7b37552/attachment.sig>


More information about the Libguestfs mailing list