From: Eric Biggers Date: Tue, 16 Dec 2014 02:33:59 +0000 (-0600) Subject: utf16le_dupz() input may be misaligned X-Git-Tag: v1.7.4~21 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=5f3757249c17cb9e2826f645e0f8618534c80fcc utf16le_dupz() input may be misaligned --- diff --git a/include/wimlib/encoding.h b/include/wimlib/encoding.h index b48fe9ce..3d3c6852 100644 --- a/include/wimlib/encoding.h +++ b/include/wimlib/encoding.h @@ -35,7 +35,7 @@ varname1##_to_##varname2##_buf(const chartype1 *in, size_t in_nbytes, \ chartype2 *out); extern utf16lechar * -utf16le_dupz(const utf16lechar *ustr, size_t usize); +utf16le_dupz(const void *ustr, size_t usize); #if !TCHAR_IS_UTF16LE DECLARE_CHAR_CONVERSION_FUNCTIONS(utf16le, tstr, utf16lechar, tchar); diff --git a/src/dentry.c b/src/dentry.c index 669b447e..862c6640 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -1342,8 +1342,7 @@ read_dentry(const u8 * restrict buf, size_t buf_len, /* Read the filename if present. Note: if the filename is empty, there * is no null terminator following it. */ if (file_name_nbytes) { - dentry->file_name = utf16le_dupz((const utf16lechar *)p, - file_name_nbytes); + dentry->file_name = utf16le_dupz(p, file_name_nbytes); if (dentry->file_name == NULL) { ret = WIMLIB_ERR_NOMEM; goto err_free_dentry; @@ -1355,8 +1354,7 @@ read_dentry(const u8 * restrict buf, size_t buf_len, /* Read the short filename if present. Note: if there is no short * filename, there is no null terminator following it. */ if (short_name_nbytes) { - dentry->short_name = utf16le_dupz((const utf16lechar *)p, - short_name_nbytes); + dentry->short_name = utf16le_dupz(p, short_name_nbytes); if (dentry->short_name == NULL) { ret = WIMLIB_ERR_NOMEM; goto err_free_dentry; diff --git a/src/encoding.c b/src/encoding.c index b54e787b..6a1148a8 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -561,9 +561,11 @@ cmp_utf16le_strings(const utf16lechar *s1, size_t n1, return (n1 < n2) ? -1 : 1; } -/* Duplicate a UTF16-LE string which may not be null-terminated. */ +/* Duplicate a UTF16-LE string. The input string might not be null terminated + * and might be misaligned, but the returned string is guaranteed to be null + * terminated and properly aligned. */ utf16lechar * -utf16le_dupz(const utf16lechar *ustr, size_t usize) +utf16le_dupz(const void *ustr, size_t usize) { utf16lechar *dup = MALLOC(usize + sizeof(utf16lechar)); if (dup) { diff --git a/src/ntfs-3g_capture.c b/src/ntfs-3g_capture.c index cd0758ac..22b9e554 100644 --- a/src/ntfs-3g_capture.c +++ b/src/ntfs-3g_capture.c @@ -393,7 +393,7 @@ set_dentry_dos_name(struct wim_dentry *dentry, const struct dos_name_map *map) if (dentry->is_win32_name) { node = lookup_dos_name(map, dentry->d_inode->i_ino); if (node) { - dentry->short_name = utf16le_dupz((const utf16lechar *)node->dos_name, + dentry->short_name = utf16le_dupz(node->dos_name, node->name_nbytes); if (!dentry->short_name) return WIMLIB_ERR_NOMEM;