X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=hivex%2Fhivex.c;h=0c09ace64cf4731bbbbfac35bf035a91f7dbc32e;hb=d0507993a7c3b39c2c86323a79eb3f4bfd2d19fb;hp=16be753b3c404c9a498f91a656021847b4634251;hpb=792c5283009ed6753239a14df9a6e9c71bea35fd;p=libguestfs.git diff --git a/hivex/hivex.c b/hivex/hivex.c index 16be753..0c09ace 100644 --- a/hivex/hivex.c +++ b/hivex/hivex.c @@ -18,18 +18,68 @@ * See file LICENSE for the full license. */ +#include + #include #include #include #include -#include #include #include #include #include #include #include -#include +#ifdef HAVE_ENDIAN_H +#include +#endif +#ifdef HAVE_BYTESWAP_H +#include +#endif + +#define STREQ(a,b) (strcmp((a),(b)) == 0) +#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) +//#define STRNEQ(a,b) (strcmp((a),(b)) != 0) +//#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) +#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) +//#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) +//#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) +//#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) +//#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#ifndef be32toh +#define be32toh(x) __bswap_32 (x) +#endif +#ifndef be64toh +#define be64toh(x) __bswap_64 (x) +#endif +#ifndef le16toh +#define le16toh(x) (x) +#endif +#ifndef le32toh +#define le32toh(x) (x) +#endif +#ifndef le64toh +#define le64toh(x) (x) +#endif +#else +#ifndef be32toh +#define be32toh(x) (x) +#endif +#ifndef be64toh +#define be64toh(x) (x) +#endif +#ifndef le16toh +#define le16toh(x) __bswap_16 (x) +#endif +#ifndef le32toh +#define le32toh(x) __bswap_32 (x) +#endif +#ifndef le64toh +#define le64toh(x) __bswap_64 (x) +#endif +#endif #include "hivex.h" @@ -55,7 +105,7 @@ struct hive_h { #define BITMAP_SET(bitmap,off) (bitmap[(off)>>5] |= 1 << (((off)>>2)&7)) #define BITMAP_CLR(bitmap,off) (bitmap[(off)>>5] &= ~ (1 << (((off)>>2)&7))) #define BITMAP_TST(bitmap,off) (bitmap[(off)>>5] & (1 << (((off)>>2)&7))) -#define IS_VALID_BLOCK(h,off) \ +#define IS_VALID_BLOCK(h,off) \ (((off) & 3) == 0 && \ (off) >= 0x1000 && \ (off) < (h)->size && \ @@ -103,7 +153,7 @@ struct ntreg_hbin_block { } __attribute__((__packed__)); #define BLOCK_ID_EQ(h,offs,eqid) \ - (strncmp (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2) == 0) + (STREQLEN (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2)) static size_t block_len (hive_h *h, size_t blkoff, int *used) @@ -195,7 +245,7 @@ hivex_open (const char *filename, int flags) h->msglvl = flags & HIVEX_OPEN_MSGLVL_MASK; const char *debug = getenv ("HIVEX_DEBUG"); - if (debug && strcmp (debug, "1") == 0) + if (debug && STREQ (debug, "1")) h->msglvl = 2; if (h->msglvl >= 2) @@ -230,6 +280,8 @@ hivex_open (const char *filename, int flags) } h->bitmap = calloc (1 + h->size / 32, 1); + if (h->bitmap == NULL) + goto error; #if 0 /* Doesn't work. */ /* Header checksum. */ @@ -683,7 +735,7 @@ hivex_node_get_child (hive_h *h, hive_node_h node, const char *nname) for (i = 0; children[i] != 0; ++i) { name = hivex_node_name (h, children[i]); if (!name) goto error; - if (strcasecmp (name, nname) == 0) { + if (STRCASEEQ (name, nname)) { ret = children[i]; break; } @@ -814,7 +866,7 @@ hivex_node_get_value (hive_h *h, hive_node_h node, const char *key) for (i = 0; values[i] != 0; ++i) { name = hivex_value_key (h, values[i]); if (!name) goto error; - if (strcasecmp (name, key) == 0) { + if (STRCASEEQ (name, key)) { ret = values[i]; break; } @@ -990,9 +1042,12 @@ windows_utf16_to_utf8 (/* const */ char *input, size_t len) size_t r = iconv (ic, &inp, &inlen, &outp, &outlen); if (r == (size_t) -1) { if (errno == E2BIG) { + size_t prev = outalloc; /* Try again with a larger output buffer. */ free (out); outalloc *= 2; + if (outalloc < prev) + return NULL; goto again; } else {