]> wimlib.net Git - wimlib/commitdiff
utf16le_dupz() input may be misaligned
authorEric Biggers <ebiggers3@gmail.com>
Tue, 16 Dec 2014 02:33:59 +0000 (20:33 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 16 Dec 2014 02:34:02 +0000 (20:34 -0600)
include/wimlib/encoding.h
src/dentry.c
src/encoding.c
src/ntfs-3g_capture.c

index b48fe9ced389568fac1f1de3da12b479d6168323..3d3c6852c82aa66e5672e6673d3be880dcd2ad58 100644 (file)
@@ -35,7 +35,7 @@ varname1##_to_##varname2##_buf(const chartype1 *in, size_t in_nbytes, \
                               chartype2 *out);
 
 extern utf16lechar *
                               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);
 
 #if !TCHAR_IS_UTF16LE
 DECLARE_CHAR_CONVERSION_FUNCTIONS(utf16le, tstr, utf16lechar, tchar);
index 669b447ea8b88a9f4cd6cc2750809f97182816aa..862c6640c9bb54b9bef52610824604091b830e13 100644 (file)
@@ -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) {
        /* 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;
                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) {
        /* 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;
                if (dentry->short_name == NULL) {
                        ret = WIMLIB_ERR_NOMEM;
                        goto err_free_dentry;
index b54e787bd4cc10a5b671146dbad7661b5e9101bc..6a1148a8dea48deaadb258a620aa285e56a8b263 100644 (file)
@@ -561,9 +561,11 @@ cmp_utf16le_strings(const utf16lechar *s1, size_t n1,
        return (n1 < n2) ? -1 : 1;
 }
 
        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 *
 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) {
 {
        utf16lechar *dup = MALLOC(usize + sizeof(utf16lechar));
        if (dup) {
index cd0758ac42302950a3159c563d3e6e4481f863ee..22b9e55422497ae85e5a45a375863d6b806482f0 100644 (file)
@@ -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) {
        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;
                                                          node->name_nbytes);
                        if (!dentry->short_name)
                                return WIMLIB_ERR_NOMEM;