[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Info-mtools] iconv and string termination: accessing files by name not
From: |
David Elliott |
Subject: |
[Info-mtools] iconv and string termination: accessing files by name not working on macOS |
Date: |
Mon, 4 Nov 2024 09:58:23 -0800 |
Hello,
There is a problem when running mtools on macOS, possibly other systems, which
appears to be caused by a misuse of iconv.
Specifically, in the unix_name function in file_name.c a 13-char buffer is
used. This is enough for the 8 + 3 + 1 dot + 1 NUL terminator. So far so good.
Most names are not the full 12 character string length, yet 12 is
unconditionally passed to dos_to_wchar. If iconv use is enabled, the input
length (len) will be assigned to a local variable (size_t in_len) whose
reference is passed as the *srcleft (second) parameter to the iconv call.
This means iconv won't stop at the NUL byte, but will attempt to convert all 12
characters. This wouldn't be noticeable if iconv converted NUL to NUL, but my
observation in the debugger is that my iconv is simply skipping over input NUL,
then converting whatever garbage characters exist after it, up to the limit.
The fix is obvious: use strlen(ans) as the input length. The NUL gets added to
the output by existing code and everything works as designed.
This manifests as a simple file not found for commands like `mdir ::/FOOBAR`
but leads to looping or even a segfault for commands like `mdir -s`, presumably
because the code is not expecting to fail to list the contents of a
subdirectory it literally just found.
-David
mtools-iconv.diff
Description: Binary data
- [Info-mtools] iconv and string termination: accessing files by name not working on macOS,
David Elliott <=