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

NULL ptr crash when inputting enough chars to wrap line when window can scroll horizontally #721

Closed
SkyLined opened this issue Feb 7, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@SkyLined
Copy link

SkyLined commented Feb 7, 2025

Steps to reproduce

  1. Configure cmd.exe to run in Windows Console Host

  2. Run cmd.exe

  3. Make sure the window can scroll horizontally:

    1. Click the icon in the console window title bar
    2. Select Properties
    3. Under Screen Buffer Size for Width enter 110
    4. Under Window Size for Width enter 100

    (The buffer size needs to be larger than the window size)

  4. Type characters (e.g. "AAAAAA...") until the end of the window so it scrolls horizontally.

  5. Continue to type characters (e.g. "AAAAAA...") until the end of the line so the line wraps.

  6. Observe clink crashing because of a NULL ptr in tputs.

Basic analysis

I am not familiar with the code, so this may be wrong.

  • tputs is called with s == NULL.

  • tputs is called by ‎‎_rl_clear_to_eol where _rl_term_clreol == NULL.
    (There is an assert to detect this but that's not in the release version and would also have caused a crash.)

  • ‎‎_rl_clear_to_eol is called from display_manager::display. Which, at the very start creates a preserve_window_scroll_position object that sets _rl_term_clreol to nullptr.
    Once the preserve_window_scroll_position is deleted, the _rl_term_clreol value will be reset to its original value. However, the code does not delete the object before calling ‎‎_rl_clear_to_eol.

Other possible issues

It appears there other other locations in the code where a preserve_window_scroll_position object is created and ‎‎_rl_clear_to_eol is called before the object is destroyed, which would cause similar issues.

@SkyLined SkyLined changed the title NULL ptr crash when inputting enough chars to scrolls window horizontally NULL ptr crash when inputting enough chars to wrap line when window can scrolls horizontally Feb 7, 2025
@SkyLined SkyLined changed the title NULL ptr crash when inputting enough chars to wrap line when window can scrolls horizontally NULL ptr crash when inputting enough chars to wrap line when window can scroll horizontally Feb 7, 2025
@chrisant996 chrisant996 added the bug Something isn't working label Feb 7, 2025
@chrisant996
Copy link
Owner

Confirmed. Thanks for reporting this. There are many ways to hit the crash when the console window width is smaller than the console screen buffer width.

This is a regression caused by some refactoring in eb37b0e in Nov 2024.

@chrisant996
Copy link
Owner

v1.7.10 has been published with a fix.

@SkyLined
Copy link
Author

SkyLined commented Feb 7, 2025

Thank you, this solves my problem!

@chrisant996
Copy link
Owner

Thank you, this solves my problem!

Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants