[libvirt] [PATCH] network: fix element size in memmove

Eric Blake eblake at redhat.com
Wed Sep 19 23:52:24 UTC 2012


On 09/19/2012 05:19 PM, Laine Stump wrote:
> The memmove to move elements in the dhcp hosts array when inserting
> and deleting items was mistakenly basing the length of the copy on the
> size of a virNetworkDHCPHostDefPtr rather than virNetworkDHCPHostDef,
> with the expected disastrous results.
> ---
> 
> We really should create a VIR_SOMETHING() macro to take care of this...
> 
>  src/conf/network_conf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index db398ae..046891c 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -2449,7 +2449,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
>          } else { /* implied (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST) */
>  
>              memmove(ipdef->hosts + 1, ipdef->hosts,
> -                    sizeof(ipdef->hosts) * ipdef->nhosts);
> +                    sizeof(*ipdef->hosts) * ipdef->nhosts);

Okay.

>              ipdef->hosts[0] = host;
>              ipdef->nhosts++;
>              memset(&host, 0, sizeof(host));
> @@ -2481,7 +2481,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
>          /* remove it */
>          virNetworkDHCPHostDefClear(&ipdef->hosts[ii]);
>          memmove(ipdef->hosts + ii, ipdef->hosts + ii + 1,
> -                sizeof(ipdef->hosts) * ipdef->nhosts - ii - 1);
> +                sizeof(*ipdef->hosts) * ipdef->nhosts - ii - 1);

Not so good.  Here, you want:

sizeof(*ipdef->hosts) * (ipdef->nhosts - ii - 1)

ACK with that additional bug fix.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120919/b39837c8/attachment-0001.sig>


More information about the libvir-list mailing list