bug-ncurses
[Top][All Lists]
Advanced

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

Re: Segmentation fault when calling function `scr_restore`


From: Thomas Dickey
Subject: Re: Segmentation fault when calling function `scr_restore`
Date: Tue, 17 Sep 2024 17:05:58 -0400

On Tue, Sep 17, 2024 at 10:52:40AM +0200, Zixi Liu wrote:
> Hi, 
> Recently, I found a segmentation fault in nurses-rs, which is a very thin 
> wrapper around the ncurses TUI lib. 
> 
> 
> When calling the function `scr_restore`, if the `filename` equals to "/" or 
> ".", it would trigger a segmentation fault without other more information. 
> Although I opened a issue in the `nurses-rs` repo, the contributor thought it 
> may be a bug in nurses.
> 
> 
> This is the issue link: https://github.com/jeaye/ncurses-rs/issues/222
> 
> 
> Thank you for your time and I look forward to your response.

In a quick check, I see that from scr_restore returns ERR for this case,
but that (according to the trace) an fopen on a directory is returning
a valid FILE* (which fails to give usable data, causing the SCREEN to
be freed and leading to a crash on the next refresh().  Some systems
will disallow that fopen, but Linux isn't doing that.

While I can (and will) add a check to ensure that's a file (rather than
a directory), it won't fix the larger problem of feeding it bad input
and the rust binding not protecting the user by doing something with
the error status.  You'll have to check the return value for stuff like
this.

(Also, reading the source for the binding is a good idea, because
there are several incompletely-implemented functions).

-- 
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net

Attachment: signature.asc
Description: PGP signature


reply via email to

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