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

Re: [Libguestfs] [hivex] [PATCH 1/2] hivex: Expose hive major and minor version



On Mon, Dec 12, 2011 at 09:59:18PM -0800, Alex Nelson wrote:
> The major and minor version were being reported in a debug message.
> This patch adds the version information to the ABI and reports with
> hivexml.
> +  "major_version", (RInt32, [AHive]),
> +    "return the major version of the hive",
> +    "\
> +Return major version stored in the hive header, -1 on error.";

You don't need to say what it returns on error, since the generator
will do this.

That's the theory.  Unfortunately the generated code for RInt32 is
wrong; although the only existing function that returns RInt32
(hivex_value_dword) returns -1 on error *and* sets errno, the
generator doesn't document this.  You'll need a small and simple patch
to the generator to fix this.

> +  /* Check minor version; if unable to decode, terminate. */
> +  int32_t minor_ver = hivex_minor_version (h);
> +  if (minor_ver < 0) {
> +    fprintf (stderr,
> +             "hivex: %s: could not decode hive minor version\n",
> +             filename);
> +    errno = EINVAL;
> +    goto error;

hivex_major_version should set the errno (see below), so you shouldn't
set it here ...

> +int32_t
> +hivex_major_version (hive_h *h)
> +{
> +  return (h && h->hdr) ? (int32_t) le32toh (h->hdr->major_ver) : -1;
> +}

I think these two functions should set errno on error, so:

int32_t
hivex_major_version (hive_h *h)
{
  if (!h || !h->hdr) {
    errno = EINVAL;
    return -1;
  }
  return le32toh (h->hdr->major_ver);
}

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.
http://et.redhat.com/~rjones/virt-df/


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