Re: [PATCH 12/12] storage_conf: Use uid_t/gid_t instead of int to cast the value

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

 



On 05/22/2013 06:05 AM, Osier Yang wrote:
> And error out if the casted value is not same with the original
> one, which prevents the bug on platform(s) where uid_t/gid_t
> has different size with long.
> ---
>  src/conf/storage_conf.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
>      } else {
> -        if (virXPathLong("number(./owner)", ctxt, &v) < 0) {
> +        if (virXPathLong("number(./owner)", ctxt, &val) < 0 ||
> +            (uid_t)val != val) {

Once you have made this check...

>              virReportError(VIR_ERR_XML_ERROR, "%s",
>                             _("malformed owner element"));
>              goto error;
>          }
> -        perms->uid = (int)v;
> +
> +        perms->uid = (uid_t)val;

...the cast here is redundant.  You could write 'perms->uid = val'.

>      }
>  
>      if (virXPathNode("./group", ctxt) == NULL) {
>          perms->gid = (gid_t) -1;
>      } else {
> -        if (virXPathLong("number(./group)", ctxt, &v) < 0) {
> +        if (virXPathLong("number(./group)", ctxt, &val) < 0 ||
> +            (gid_t)val != val) {
>              virReportError(VIR_ERR_XML_ERROR, "%s",
>                             _("malformed group element"));
>              goto error;
>          }
> -        perms->gid = (int)v;
> +        perms->gid = (gid_t)val;

Likewise.

ACK with that simplification, and with your followup that explicitly
allows -1.

-- 
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]