Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes TChDirDialog on Linux handle native Linux paths (and fix crash) #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MookThompson
Copy link
Contributor

Hi magliblot,

For the record, here are the hacky changes I made to get the TChDirDialog to work on Linux with native paths (and not crash when doing so). For my use, I don't need/want the Linux TChDirDialog to handle Windows paths, so it doesn't (eg it should accept names with the valid-on-Linux '\' char in it without assuming that's a directory separator). Because I don't need to support Windows paths on Linux, it's also switched based on the existing _TV_UNIX #define, rather than some runtime flag.

The fix for the crash is the "if ( end == NULL )" check in source/tvision/tdirlist.cpp.

As discussed, there could well be other places where the 'Windows paths on Linux' is still assumed - I've just done what I needed to get the TChDirDialog up and running as I wanted it.

Hope this helps you do it properly if you get chance to look at it at some point.
Mark

…inux path (eg /home), makes TDirListBox work properly on Linux (no C:\ drives etc)

Fixes segfault on Linux if you call  TDirListBox::newDirectory() with a real Unix-style path.
Makes the TChDirDialog support native Linux paths (no simulated C:\ drive etc).
@jengelh
Copy link

jengelh commented May 17, 2024

This does not fix the crash for me. ASAN still reports an issue.

=================================================================
==64147==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x507000000a74 at pc 0x7f228aca97a1 bp 0x7ffc9a2996a0 sp 0x7ffc9a298e60
WRITE of size 120 at 0x507000000a74 thread T0
    #0 0x7f228aca97a0  (/lib64/libasan.so.8+0xa97a0) (BuildId: 183f53e480d86b3f4e532dc084c6a3c77ec09062)
    #1 0x4ee818 in TChDirDialog::setUpDialog() ~/source/tvision/tchdrdlg.cpp:158
    #2 0x4ebc8d in TChDirDialog::TChDirDialog(unsigned short, unsigned short) ~/source/tvision/tchdrdlg.cpp:69
    #3 0x41d261 in TVDemo::changeDir() ~/examples/tvdemo/tvdemo2.cpp:225
    #4 0x41a47b in TVDemo::handleEvent(TEvent&) ~/examples/tvdemo/tvdemo2.cpp:89
    #5 0x555179 in TGroup::execute() ~/source/tvision/tgroup.cpp:181
    #6 0x5f010e in TProgram::run() ~/source/tvision/tprogram.cpp:312
    #7 0x4119df in main ~/examples/tvdemo/tvdemo1.cpp:62
    #8 0x7f2289c2a1ef in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #9 0x7f2289c2a2b8 in __libc_start_main_impl ../csu/libc-start.c:360
    #10 0x408094 in _start ../sysdeps/x86_64/start.S:115

0x507000000a74 is located 0 bytes after 68-byte region [0x507000000a30,0x507000000a74)
allocated by thread T0 here:
    #0 0x7f228acfc338 in operator new[](unsigned long) (/lib64/libasan.so.8+0xfc338) (BuildId: 183f53e480d86b3f4e532dc084c6a3c77ec09062)
    #1 0x57262d in TInputLine::TInputLine(TRect const&, unsigned int, TValidator*, unsigned short) ~/source/tvision/tinputli.cpp:84
    #2 0x4e9619 in TChDirDialog::TChDirDialog(unsigned short, unsigned short) ~/source/tvision/tchdrdlg.cpp:50
    #3 0x41d261 in TVDemo::changeDir() ~/examples/tvdemo/tvdemo2.cpp:225
    #4 0x41a47b in TVDemo::handleEvent(TEvent&) ~/examples/tvdemo/tvdemo2.cpp:89
    #5 0x555179 in TGroup::execute() ~/source/tvision/tgroup.cpp:181
    #6 0x5f010e in TProgram::run() ~/source/tvision/tprogram.cpp:312
    #7 0x4119df in main ~/examples/tvdemo/tvdemo1.cpp:62
    #8 0x7f2289c2a1ef in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
            trimEndSeparator( curDir );
**          strcpy( dirInput->data, curDir );
            dirInput->drawView();

After cherry-picking d0d645f onto d1fa783, ASAN still flags the very same line.

magiblot added a commit that referenced this pull request May 21, 2024
@magiblot
Copy link
Owner

Hi everyone!

First of all, @MookThompson, excuse me for not having replied in a very long time. Thanks for sharing your solution. In my opinion, TChDirDialog implements an outdated concept that no modern user expects to find in (barely) any application these days. That's why I didn't bother integrating Unix paths into it. I still think it's not worth spending much effort into it.

However, I agree that there is no point in displaying drive letters. I fixed this in 545bc7d. Switching from backslashes to forward slashes requires making deeper changes, so I am skipping that for now. Compatibility with Windows paths is tied to the public specification of the Turbo Vision-provided path manipulation functions (fexpand, getCurDir...). Since it is highly discouraged to use these functions anyway (e.g. they rely on buffers limited to MAXPATH characters), I prefer to at least preserve their expected behavior. For example, getCurDir is expected to return a path including a drive letter, so the changes in your solution could break code elsewhere.

Secondly, @jengelh, thanks for the report although the crash you described was not related to the changes in this pull request. Nevertheless, I attempted to fix it in e5b8d3f, although I'm afraid that TChDirDialog (and all the code related to file paths in general) is still vulnerable to memory safety issues due to the prevalence of unsafe string manipulation operations.

Cheers.

@MookThompson
Copy link
Contributor Author

MookThompson commented May 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants