info-mtools
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Info-mtools] iconv and string termination: accessing files by name


From: Alain Knaff
Subject: Re: [Info-mtools] iconv and string termination: accessing files by name not working on macOS
Date: Thu, 21 Nov 2024 08:49:04 +0100
User-agent: Mozilla Thunderbird

Hi,

On 04/11/2024 18:58, David Elliott wrote:
> 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
> 
> 
> 
> 

Thanks for the heads-up. This is now fixed in 4.0.46, along with a
similar issue in the call from unix_normalize to dos_to_wchar (where it
was actually worse, as it overwrite one byte after the buffer)

Regards,

Alain



reply via email to

[Prev in Thread] Current Thread [Next in Thread]