-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Use-after-free of the screen encoding in the _curses module #151695
Copy link
Copy link
Open
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Fields
Give feedbackNo fields configured for issues without a type.
Bug report
The module-global
curses_screen_encodinginModules/_cursesmodule.cstores a borrowed pointer to theencodingstring owned by the window object thatinitscr()returns:It is set only on the first
initscr()call and is never updated afterwards. That first window object can be deallocated while the pointer is still needed: the module-level functionsunctrl()andungetch()have no window of their own and fall back tocurses_screen_encodingto encode non-ASCII characters. Once the originating window is gone, those functions read freed memory.It can be reached from Python by dropping the initial screen and then encoding a non-ASCII character, e.g.:
The fix is to keep a private copy of the encoding instead of borrowing the window's, refreshed on every
initscr()and released when the module is torn down.Linked PRs