Re: [PATCH] maint: avoid potential promotion issues with [ug]id_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/07/2013 08:12 PM, Guannan Ren wrote:
>> * src/locking/lock_driver_sanlock.c
>> (virLockManagerSanlockSetupLockspace, virLockManagerSanlockInit)
>> (virLockManagerSanlockCreateLease): Cast -1 to proper type before
>> comparing with uid_t or gid_t.

> 
>     According to GUN C library
>     "uid_t This is an integer data type used to represent user IDs.
>              In the GNU library, this is an alias for unsigned int."
>      So driver->user = -1 will lead to wrong value.

No, actually 'driver->user = -1' is always the right value, no matter
what type uid_t is, because of C promotion rules (C guarantees that -1
promotes to the all-bits-set version of any unsigned type of any width).
 Where you get into problems is 'driver->user = driver->group = -1', in
the theoretical platform where driver->group is narrower than
driver->user and both types are unsigned (then you could end up with
0xffff instead of the intended 0xffffffff for driver->user).  Likewise,
on a platform where gid_t is 16-bit unsigned, then (gid_t)-1 == -1
promotes to '0xffff == -1' which is false.  Thankfully, I don't know of
any such perverse platforms, but better safe than sorry.

> 
> http://pubs.opengroup.org/onlinepubs/000095399/functions/chown.html
>      use (uid_t) -1 too.
> 
>      ACK.

Pushed.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]