[Libguestfs] [PATCH 3/3] lib: Add support for creating nodes (keys) and values with UTF-16LE-encoded names
Hilko Bengen
bengen at hilluzination.de
Mon Nov 25 21:52:30 UTC 2013
* Richard W.M. Jones:
>> - nk->name_len = htole16 (strlen (name));
>> - strcpy (nk->name, name);
>> + nk->name_len = htole16 (recoded_name_len);
>> + memcpy (nk->name, recoded_name, recoded_name_len);
>> + free(recoded_name);
>
> Please put spaces after function names! It improves readability:
Sorry, I'll fix those. I also forgot to add a free() in
hivex_node_set_values.
>> /* Update max_subkey_name_len in parent nk. */
>> - uint16_t max = le16toh (parent_nk->max_subkey_name_len);
>> - if (max < strlen (name) * 2) /* *2 because "recoded" in UTF16-LE. */
>> - parent_nk->max_subkey_name_len = htole16 (strlen (name) * 2);
>> + size_t utf16_len = use_utf16 ? recoded_name_len : recoded_name_len * 2;
>
> * 2 is probably wrong here for non-BMP characters, but the original
> code makes the same mistake ... Could we get the true length from the
> hivex_encode_string function?
Are there any non-BMP characters that can be encoded in Latin1 -- or
whatever 1-byte encoding one is supposed to use there?
Peter Norris' master's thesis[1] suggests that
recoded_name_len : recoded_name_len * 2
is probably right.
Cheers,
-Hilko
[1] http://amnesia.gtisc.gatech.edu/~moyix/suzibandit.ltd.uk/MSc/Registry%20Structure%20-%20Main%20V4.pdf, p.79
More information about the Libguestfs
mailing list