[libvirt] PATCH: Fix misc memory alloc/free/usage bugs

Ryota Ozaki ozaki.ryota at gmail.com
Mon Mar 30 14:41:20 UTC 2009


Hi Daniel,

On Mon, Mar 30, 2009 at 10:39 PM, Daniel P. Berrange
<berrange at redhat.com> wrote:
> A few more small bugs
>
>  * src/node_device.c: Don't strdup() a NULL device parent
>  * src/qemu_conf.c: Don't try to run access() on a NULL binary path
>  * src/security_selinux.c Make sure result from readlink() is NULL
>   terminated
>  * src/storage_conf.c: DOn't free 'mode' while it is still used
>
>
>
> diff -r b73fe666feff src/node_device.c
> --- a/src/node_device.c Fri Mar 27 16:14:49 2009 +0000
> +++ b/src/node_device.c Mon Mar 30 14:37:45 2009 +0100
> @@ -176,9 +176,14 @@ static char *nodeDeviceGetParent(virNode
>         goto cleanup;
>     }
>
> -    ret = strdup(obj->def->parent);
> -    if (!ret)
> -        virReportOOMError(dev->conn);
> +    if (obj->def->parent) {
> +        ret = strdup(obj->def->parent);
> +        if (!ret)
> +            virReportOOMError(dev->conn);
> +    } else {
> +        virNodeDeviceReportError(dev->conn, VIR_ERR_INTERNAL_ERROR,
> +                                 "%s", _("no parent for this device"));
> +    }
>
>  cleanup:
>     if (obj)
> diff -r b73fe666feff src/qemu_conf.c
> --- a/src/qemu_conf.c   Fri Mar 27 16:14:49 2009 +0000
> +++ b/src/qemu_conf.c   Mon Mar 30 14:37:45 2009 +0100
> @@ -269,7 +269,7 @@ qemudCapsInitGuest(virCapsPtr caps,
>      * which can be used with magic cpu choice
>      */
>     hasbase = (access(info->binary, X_OK) == 0);
> -    hasaltbase = (access(info->altbinary, X_OK) == 0);
> +    hasaltbase = (info->altbinary && access(info->altbinary, X_OK) == 0);
>
>     /* Can use acceleration for KVM/KQEMU if
>      *  - host & guest arches match
> diff -r b73fe666feff src/security_selinux.c
> --- a/src/security_selinux.c    Fri Mar 27 16:14:49 2009 +0000
> +++ b/src/security_selinux.c    Mon Mar 30 14:37:45 2009 +0100
> @@ -303,11 +303,13 @@ SELinuxRestoreSecurityImageLabel(virConn
>         return -1;
>
>     if (S_ISLNK(buf.st_mode)) {
> +        int n;
>         if (VIR_ALLOC_N(newpath, buf.st_size + 1) < 0)
>             return -1;
>
> -        if (readlink(path, newpath, buf.st_size) < 0)
> +        if ((n =readlink(path, newpath, buf.st_size)) < 0)
>             goto err;
> +        buf.st_size[n] = '\0';
           newpath[n] = '\0';

correct?

>         path = newpath;
>         if (stat(path, &buf) != 0)
>             goto err;
> diff -r b73fe666feff src/storage_conf.c
> --- a/src/storage_conf.c        Fri Mar 27 16:14:49 2009 +0000
> +++ b/src/storage_conf.c        Mon Mar 30 14:37:45 2009 +0100
> @@ -401,12 +401,13 @@ virStorageDefParsePerms(virConnectPtr co
>     } else {
>         char *end = NULL;
>         perms->mode = strtol(mode, &end, 8);
> -        VIR_FREE(mode);
>         if (*end || perms->mode < 0 || perms->mode > 0777) {
> +            VIR_FREE(mode);
>             virStorageReportError(conn, VIR_ERR_XML_ERROR,
>                                   "%s", _("malformed octal mode"));
>             goto error;
>         }
> +        VIR_FREE(mode);
>     }
>
>     if (virXPathNode(conn, "./owner", ctxt) == NULL) {
>
>
> Daniel
> --
> |: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
> |: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
> |: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
> |: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
>
> --
> Libvir-list mailing list
> Libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>




More information about the libvir-list mailing list