Mantis Bug Tracker

View Revisions: Issue #10270 All Revisions ] Back to Issue ]
Summary 0010270: libgraphics.so dlopen()ing libncursesw.so.5 instead of .so.6 can segfault on some systems with PRINT_MODE:TEXT
Revision 2017-07-28 11:06 by lethosor
Description I tried to launch DF in text mode after some time and find that it crashes instantly.

After some time spent researching the problem, I see that the game and libgraphics.so are linked to libncurses(w).so.6, while libgraphics.so tries to dlopen .so.5. Both ncurses 5 and 6 are installed at the same time on this machine (slotted), as per standard gentoo repo. The crash doesn't occur if a symlink is used to trick it into thinking it found .so.5, despite it being .so.6, hence it seems that the wrong version is being opened in libgraphics.

The library also tried to dlopen libncursesw.so (which it does try if I uninstall ncurses 5 from the system), but inexplicably fails here as it doesn't seem to be a symlink here but an LD script and proclaims "Didn't find any flavor of libncursesw, attempting libncurses" and then "Unable to open any flavor of libncurses!" before exiting cleanly. Again, a symlink in /lib/ (or df/libs) with that name pointing to the right shared object resolves the problem. If that symlink points to ncurses 5 (.so.5), it crashes.

TL;DR: Add some lines in g_src/renderer_curses.cpp

Patch:

--- a/g_src/renderer_curses.cpp
+++ b/g_src/renderer_curses.cpp
@@ -294,7 +294,7 @@ extern "C" {
     if (!stub_initialized) {

       stub_initialized = true;

       // We prefer libncursesw, but we'll accept libncurses if we have to

+ handle = dlopen("libncursesw.so.6", RTLD_LAZY);

+ if (handle) goto opened;

      handle = dlopen("libncursesw.so.5", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncursesw.so", RTLD_LAZY);

       if (handle) goto opened;

@@ -302,7 +302,7 @@ extern "C" {
       sleep(5);

       handle = dlopen("libncurses.dylib", RTLD_LAZY);

       if (handle) goto opened;

+ handle = dlopen("libncurses.so.6", RTLD_LAZY);

+ if (handle) goto opened;

       handle = dlopen("libncurses.so.5", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncurses.so", RTLD_LAZY);

       if (handle) goto opened;

Revision 2017-07-28 11:06 by lethosor
Description I tried to launch DF in text mode after some time and find that it crashes instantly.

After some time spent researching the problem, I see that the game and libgraphics.so are linked to libncurses(w).so.6, while libgraphics.so tries to dlopen .so.5. Both ncurses 5 and 6 are installed at the same time on this machine (slotted), as per standard gentoo repo. The crash doesn't occur if a symlink is used to trick it into thinking it found .so.5, despite it being .so.6, hence it seems that the wrong version is being opened in libgraphics.

The library also tried to dlopen libncursesw.so (which it does try if I uninstall ncurses 5 from the system), but inexplicably fails here as it doesn't seem to be a symlink here but an LD script and proclaims "Didn't find any flavor of libncursesw, attempting libncurses" and then "Unable to open any flavor of libncurses!" before exiting cleanly. Again, a symlink in /lib/ (or df/libs) with that name pointing to the right shared object resolves the problem. If that symlink points to ncurses 5 (.so.5), it crashes.

TL;DR: Add some lines in g_src/renderer_curses.cpp

Patch:

--- a/g_src/renderer_curses.cpp
+++ b/g_src/renderer_curses.cpp
@@ -294,7 +294,7 @@ extern "C" {
     if (!stub_initialized) {

       stub_initialized = true;

       // We prefer libncursesw, but we'll accept libncurses if we have to

+ handle = dlopen("libncursesw.so.6", RTLD_LAZY);

+ if (handle) goto opened;

      handle = dlopen("libncursesw.so.5", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncursesw.so", RTLD_LAZY);

       if (handle) goto opened;

@@ -302,7 +302,7 @@ extern "C" {
       sleep(5);

       handle = dlopen("libncurses.dylib", RTLD_LAZY);

       if (handle) goto opened;

+ handle = dlopen("libncurses.so.6", RTLD_LAZY);

+ if (handle) goto opened;

       handle = dlopen("libncurses.so.5", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncurses.so", RTLD_LAZY);

       if (handle) goto opened;

Revision 2017-07-28 11:04 by lethosor
Description I tried to launch DF in text mode after some time and find that it crashes instantly.

After some time spent researching the problem, I see that the game and libgraphics.so are linked to libncurses(w).so.6, while libgraphics.so tries to dlopen .so.5. Both ncurses 5 and 6 are installed at the same time on this machine (slotted), as per standard gentoo repo. The crash doesn't occur if a symlink is used to trick it into thinking it found .so.5, despite it being .so.6, hence it seems that the wrong version is being opened in libgraphics.

The library also tried to dlopen libncursesw.so (which it does try if I uninstall ncurses 5 from the system), but inexplicably fails here as it doesn't seem to be a symlink here but an LD script and proclaims "Didn't find any flavor of libncursesw, attempting libncurses" and then "Unable to open any flavor of libncurses!" before exiting cleanly. Again, a symlink in /lib/ (or df/libs) with that name pointing to the right shared object resolves the problem. If that symlink points to ncurses 5 (.so.5), it crashes.

<del>TL;DR: Change 2 characters in g_src/renderer_curses.cpp</del>

Patch:

--- a/g_src/renderer_curses.cpp
+++ b/g_src/renderer_curses.cpp
@@ -294,7 +294,7 @@ extern "C" {
     if (!stub_initialized) {

       stub_initialized = true;

       // We prefer libncursesw, but we'll accept libncurses if we have to

- handle = dlopen("libncursesw.so.5", RTLD_LAZY);

+ handle = dlopen("libncursesw.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncursesw.so", RTLD_LAZY);

       if (handle) goto opened;

@@ -302,7 +302,7 @@ extern "C" {
       sleep(5);

       handle = dlopen("libncurses.dylib", RTLD_LAZY);

       if (handle) goto opened;

- handle = dlopen("libncurses.so.5", RTLD_LAZY);

+ handle = dlopen("libncurses.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncurses.so", RTLD_LAZY);

       if (handle) goto opened;

Revision 2017-07-28 11:04 by lethosor
Description I tried to launch DF in text mode after some time and find that it crashes instantly.

After some time spent researching the problem, I see that the game and libgraphics.so are linked to libncurses(w).so.6, while libgraphics.so tries to dlopen .so.5. Both ncurses 5 and 6 are installed at the same time on this machine (slotted), as per standard gentoo repo. The crash doesn't occur if a symlink is used to trick it into thinking it found .so.5, despite it being .so.6, hence it seems that the wrong version is being opened in libgraphics.

The library also tried to dlopen libncursesw.so (which it does try if I uninstall ncurses 5 from the system), but inexplicably fails here as it doesn't seem to be a symlink here but an LD script and proclaims "Didn't find any flavor of libncursesw, attempting libncurses" and then "Unable to open any flavor of libncurses!" before exiting cleanly. Again, a symlink in /lib/ (or df/libs) with that name pointing to the right shared object resolves the problem. If that symlink points to ncurses 5 (.so.5), it crashes.

<s>TL;DR: Change 2 characters in g_src/renderer_curses.cpp</s>

Patch:

--- a/g_src/renderer_curses.cpp
+++ b/g_src/renderer_curses.cpp
@@ -294,7 +294,7 @@ extern "C" {
     if (!stub_initialized) {

       stub_initialized = true;

       // We prefer libncursesw, but we'll accept libncurses if we have to

- handle = dlopen("libncursesw.so.5", RTLD_LAZY);

+ handle = dlopen("libncursesw.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncursesw.so", RTLD_LAZY);

       if (handle) goto opened;

@@ -302,7 +302,7 @@ extern "C" {
       sleep(5);

       handle = dlopen("libncurses.dylib", RTLD_LAZY);

       if (handle) goto opened;

- handle = dlopen("libncurses.so.5", RTLD_LAZY);

+ handle = dlopen("libncurses.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncurses.so", RTLD_LAZY);

       if (handle) goto opened;

Revision 2017-07-25 16:25 by lethosor
Description I tried to launch DF in text mode after some time and find that it crashes instantly.

After some time spent researching the problem, I see that the game and libgraphics.so are linked to libncurses(w).so.6, while libgraphics.so tries to dlopen .so.5. Both ncurses 5 and 6 are installed at the same time on this machine (slotted), as per standard gentoo repo. The crash doesn't occur if a symlink is used to trick it into thinking it found .so.5, despite it being .so.6, hence it seems that the wrong version is being opened in libgraphics.

The library also tried to dlopen libncursesw.so (which it does try if I uninstall ncurses 5 from the system), but inexplicably fails here as it doesn't seem to be a symlink here but an LD script and proclaims "Didn't find any flavor of libncursesw, attempting libncurses" and then "Unable to open any flavor of libncurses!" before exiting cleanly. Again, a symlink in /lib/ (or df/libs) with that name pointing to the right shared object resolves the problem. If that symlink points to ncurses 5 (.so.5), it crashes.

TL;DR: Change 2 characters in g_src/renderer_curses.cpp

Patch:

--- a/g_src/renderer_curses.cpp
+++ b/g_src/renderer_curses.cpp
@@ -294,7 +294,7 @@ extern "C" {
     if (!stub_initialized) {

       stub_initialized = true;

       // We prefer libncursesw, but we'll accept libncurses if we have to

- handle = dlopen("libncursesw.so.5", RTLD_LAZY);

+ handle = dlopen("libncursesw.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncursesw.so", RTLD_LAZY);

       if (handle) goto opened;

@@ -302,7 +302,7 @@ extern "C" {
       sleep(5);

       handle = dlopen("libncurses.dylib", RTLD_LAZY);

       if (handle) goto opened;

- handle = dlopen("libncurses.so.5", RTLD_LAZY);

+ handle = dlopen("libncurses.so.6", RTLD_LAZY);

       if (handle) goto opened;

       handle = dlopen("libncurses.so", RTLD_LAZY);

       if (handle) goto opened;



Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker