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

[bug] Segmentation fault within the ncurses console because of a race condition #350

Open
lowlevl opened this issue Oct 26, 2023 · 1 comment

Comments

@lowlevl
Copy link

lowlevl commented Oct 26, 2023

Hi,

I'm trying to package glslviewer for Alpine Linux, and while testing the application, I noticed that when compiled with ncurses, rapidly typing random characters in the glslviewer console would cause a crash with a segmentation fault, here is the stack trace:

#0  memcpy () at src/string/x86_64/memcpy.s:18
#1  0x00007ffff7fb337f in sn_write (f=0x7fffffffd5e0, s=0x7fffe5d1fc70 "%", l=439211896) at src/stdio/vsnprintf.c:25
#2  0x00007ffff7fb0872 in out (l=439211896, s=0x7fffe5d1fc70 "%", f=0x7fffffffd5e0) at src/stdio/vfprintf.c:135
#3  printf_core (f=f@entry=0x7fffffffd5e0, fmt=fmt@entry=0x7fffe5d1fc70 "%", ap=ap@entry=0x7fffffffd448, nl_arg=nl_arg@entry=0x7fffffffd4e0,
    nl_type=nl_type@entry=0x7fffffffd460) at src/stdio/vfprintf.c:639
#4  0x00007ffff7fb0a0b in vfprintf (f=f@entry=0x7fffffffd5e0, fmt=0x7fffe5d1fc70 "%", ap=<optimized out>) at src/stdio/vfprintf.c:688
#5  0x00007ffff7fb3479 in vsnprintf (s=<optimized out>, n=n@entry=2147483647, fmt=<optimized out>, ap=ap@entry=0x7fffffffd6e8) at src/stdio/vsnprintf.c:54
#6  0x00007ffff7fb3491 in vsprintf (s=<optimized out>, fmt=<optimized out>, ap=ap@entry=0x7fffffffd6e8) at src/stdio/vsprintf.c:6
#7  0x00007ffff7fae416 in sprintf (s=<optimized out>, fmt=<optimized out>) at src/stdio/sprintf.c:9
#8  0x00007ffff7f2d506 in ?? () from /usr/lib/libncursesw.so.6
#9  0x00007ffff7f2f07e in _nc_tiparm () from /usr/lib/libncursesw.so.6
#10 0x00007ffff7f12c4b in ?? () from /usr/lib/libncursesw.so.6
#11 0x00007ffff7f13bba in _nc_do_color_sp () from /usr/lib/libncursesw.so.6
#12 0x00007ffff7f25cae in vid_puts_sp () from /usr/lib/libncursesw.so.6
#13 0x00007ffff7f1ff7e in ?? () from /usr/lib/libncursesw.so.6
#14 0x00007ffff7f20333 in ?? () from /usr/lib/libncursesw.so.6
#15 0x00007ffff7f2090c in ?? () from /usr/lib/libncursesw.so.6
#16 0x00007ffff7f2181a in ?? () from /usr/lib/libncursesw.so.6
#17 0x00007ffff7f21e93 in ?? () from /usr/lib/libncursesw.so.6
#18 0x00007ffff7f235ea in doupdate_sp () from /usr/lib/libncursesw.so.6
#19 0x00007ffff7f1b0fa in wrefresh () from /usr/lib/libncursesw.so.6
#20 0x0000555555608da3 in console_uniforms_refresh() ()
#21 0x00005555555db3f6 in loop() ()
#22 0x00005555555d77b9 in main ()

while diving a bit into the code, I noticed two things:

  • The ncurses windows are global variables that aren't protected by mutexes.
  • Both the main loop() and the cinWatcherThread(), which runs in another thread act on those variables, creating a race condition.

This race condition cause segmentation faults when passing the window to the wrefresh method of ncurses.

I also confirmed this does not happen when passing the --noncurses flag or disabling ncurses at the compilation step.

@lowlevl
Copy link
Author

lowlevl commented Oct 26, 2023

This might be a duplicate or related to #323.

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

No branches or pull requests

1 participant