Re: [PATCH 2/4] lxc: add LXC version 3 network parser

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

 



On Mon, Jan 27, 2020 at 11:25:47AM -0300, Julio Faracco wrote:
> LXC version 3 or higher introduced indexes for network interfaces.
> Libvirt should be able to parse entries like `lxc.net.2.KEY`. This
> commit adds functions to parse this type of field. That's why array
> structures are so important this time.
> 
> Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx>
> ---
>  src/lxc/lxc_native.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
> index 1102928705..ae8d3cb85d 100644
> --- a/src/lxc/lxc_native.c
> +++ b/src/lxc/lxc_native.c
> @@ -649,6 +649,49 @@ lxcNetworkParseDataSuffix(const char *entry,
>  }
>  
>  
> +static lxcNetworkParseDataPtr
> +lxcNetworkGetParseDataByIndex(lxcNetworkParseDataArray *networks,
> +                              unsigned int index)
> +{
> +    size_t ndata = networks->ndata;
> +    size_t i;
> +
> +    for (i = 0; i < ndata; i++) {
> +        if (networks->parseData[i]->index == index)
> +            return networks->parseData[i];
> +    }
> +
> +    /* Index was not found. So, it is time to add new *
> +     * interface and return this last position.       */
> +    if (VIR_EXPAND_N(networks->parseData, networks->ndata, 1) < 0)
> +        return NULL;
> +
> +    networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1);
> +    networks->parseData[ndata]->index = index;
> +
> +    return networks->parseData[ndata];
> +}
> +
> +
> +static int
> +lxcNetworkParseDataEntry(const char *name,
> +                         virConfValuePtr value,
> +                         lxcNetworkParseDataArray *networks)
> +{
> +    lxcNetworkParseData *parseData;
> +    const char *suffix = STRSKIP(name, "lxc.net.");
> +    size_t index;
> +
> +    suffix = strchr(suffix, '.') + 1;
> +    sscanf(name, "lxc.net.%zu", &index);

Not checking sscanf result is dangerous.

Instead of these 2 lines you ought to be able todo

   if (virStrToLong_ull(suffix, &suffix, 10, &index) < 0)
      ...report error...

   if (suffix != '.')
      ...report error.

   suffix++;

> +
> +    if (!(parseData = lxcNetworkGetParseDataByIndex(networks, index)))
> +        return -1;
> +
> +    return lxcNetworkParseDataSuffix(suffix, value, parseData);
> +}
> +

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|





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

  Powered by Linux