Re: [Libguestfs] [PATCH 2/7] lib: Use vk->len for string conversion

Richard W.M. Jones
Mon, 13 Jan 2014 13:17:52 -0000

On Sat, Jan 11, 2014 at 12:12:47AM +0100, Hilko Bengen
wrote:
> ---
>  lib/value.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/lib/value.c b/lib/value.c
> index 65404d7..e700c84 100644
> --- a/lib/value.c
> +++ b/lib/value.c
> @@ -207,14 +207,8 @@ hivex_value_key (hive_h *h, hive_value_h value)
>    struct ntreg_vk_record *vk >      (struct ntreg_vk_record *) ((char
*) h->addr + value);
>
> -  /* AFAIK the key is always plain ASCII, so no conversion to UTF-8 is
> -   * necessary.  However we do need to nul-terminate the string.
> -   */
> -  errno = 0;
> -  size_t len = hivex_value_key_len (h, value);
> -  if (len == 0 && errno != 0)
> -    return NULL;
>    size_t flags = le16toh (vk->flags);
> +  size_t len = le16toh (vk->name_len);

I think this effectively removes a check.  hivex_value_key_len
contains this code:

  size_t seg_len = block_len (h, value, NULL);
  if (sizeof (struct ntreg_vk_record) + len - 1 > seg_len) {
    SET_ERRNO (EFAULT, "key length is too long (%zu, %zu)", len,
seg_len);
    return 0;
  }

but after this change, this would no longer be run, so it would be
possible to overrun the registry, or at least overrun the end of a
block.

Is there a reason for this patch?  It seems like just an optimization.

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.