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

Segfault when running Profanity 0.9.0 #1357

Closed
gjabell opened this issue Jun 9, 2020 · 29 comments
Closed

Segfault when running Profanity 0.9.0 #1357

gjabell opened this issue Jun 9, 2020 · 29 comments
Assignees
Labels
Milestone

Comments

@gjabell
Copy link

gjabell commented Jun 9, 2020

Expected Behavior

  • Profanity should start normally

Current Behavior

  • Profanity fails with a segfault at g_string_new from src/config/files.c:57 (related to XDG_CONFIG_HOME).
Full backtrace
(gdb) bt full
#0  0x00007ffff78920d2 in g_string_new () at /usr/lib/libglib-2.0.so.0
#1  0x00005555555dc166 in files_create_directories () at src/config/files.c:57
        xdg_config = 0x55698f20 <error: Cannot access memory at address 0x55698f20>
        xdg_data = 0xfffffffff774e920 <error: Cannot access memory at address 0xfffffffff774e920>
        themes_dir = <optimized out>
        icons_dir = <optimized out>
        chatlogs_dir = <optimized out>
        logs_dir = <optimized out>
        plugins_dir = <optimized out>
#2  0x000055555558a4ae in _init (theme_name=0x0, log_file=0x0, config_file=0x0, log_level=0x5555555f7172 "INFO")
    at src/profanity.c:175
        prof_log_level = <optimized out>
        line = <optimized out>
#3  prof_run (log_level=0x5555555f7172 "INFO", account_name=0x0, config_file=0x0, log_file=0x0, theme_name=0x0)
    at src/profanity.c:100
        line = <optimized out>
#4  0x000055555558631d in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:180
        entries =
            {{long_name = 0x5555555f7f39 "version", short_name = 118 'v', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x55555568fd70 <version>, description = 0x55555561be6e "Show version information", arg_description = 0x0}, {long_name = 0x555555605c56 "account", short_name = 97 'a', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x55555568fd58 <account_name>, description = 0x55555561c0b8 "Auto connect to an account on startup", arg_description = 0x0}, {long_name = 0x55555561b3d7 "log", short_name = 108 'l', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x55555568fd68 <log>, description = 0x55555561c0e0 "Set logging levels, DEBUG, INFO (default), WARN, ERROR", arg_description = 0x55555561be87 "LEVEL"}, {long_name = 0x555555616798 "config", short_name = 99 'c', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x55555568fd50 <config_file>, description = 0x55555561c118 "Use an alternative configuration file", arg_description = 0x0}, {long_name = 0x55555561be8d "logfile", short_name = 102 'f', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x55555568fd60 <log_file>, description = 0x55555561be95 "Specify log filename", arg_description = 0x0}, {long_name = 0x555555605fde "theme", short_name = 116 't', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x55555568fd48 <theme_name>, description = 0x55555561beaa "Specify theme name", arg_description = 0x0}, {long_name = 0x0, short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x0, description = 0x0, arg_description = 0x0}}
        error = 0x0
        context = 0x555555698f20

Possible Solution

Seems to be related to failing to find the configuration directory, even when XDG_CONFIG_HOME is set properly. Note that this still occurs after moving my current configuration to start with a fresh slate.

This wasn't an issue in 0.8.1, so it must be something that changed between 0.8.1 and 0.9.0.

Steps to Reproduce (for bugs)

  1. Run profanity

Environment

Profanity, version 0.9.0
Build information:
XMPP library: libmesode
Desktop notification support: Enabled
OTR support: Enabled (libotr 4.1.1)
PGP support: Enabled (libgpgme 1.13.1)
OMEMO support: Enabled
C plugins: Enabled
Python plugins: Disabled
GTK icons: Enabled

OS: Alpine Linux Edge
glib: 2.64.3

@jubalh
Copy link
Member

jubalh commented Jun 9, 2020

Now that was quick haha :-)
I give it a look tomorrow. Thanks for the report!

@gjabell
Copy link
Author

gjabell commented Jun 9, 2020

Thanks :) let me know if I can do anything to help debug!

@jubalh jubalh self-assigned this Jun 9, 2020
@jubalh jubalh added the bug label Jun 9, 2020
@jubalh
Copy link
Member

jubalh commented Jun 9, 2020

Maybe try using ./configure-debug then the variables in the backtrace shouldn't be optimized out.

@gjabell
Copy link
Author

gjabell commented Jun 9, 2020

Here's the backtrace with debug enabled:

Click to show
(gdb) bt full
#0  0x00007ffff78920d2 in g_string_new () at /usr/lib/libglib-2.0.so.0
#1  0x00005555555f8a69 in files_create_directories () at src/config/files.c:57
        xdg_config = 0xfffffffff7b287e0 <error: Cannot access memory at address 0xfffffffff7b287e0>
        xdg_data = 0xfffffffff7b287a0 <error: Cannot access memory at address 0xfffffffff7b287a0>
        themes_dir = 0x0
        icons_dir = 0x0
        chatlogs_dir = 0x0
        logs_dir = 0x10000000
        plugins_dir = 0x0
#2  0x000055555558b714 in _init (log_level=0x5555556455a6 "INFO", config_file=0x0, log_file=0x0, theme_name=0x0)
    at src/profanity.c:175
        prof_log_level = 67108865
#3  0x000055555558b520 in prof_run
    (log_level=0x5555556455a6 "INFO", account_name=0x0, config_file=0x0, log_file=0x0, theme_name=0x0) at src/profanity.c:100
        line = 0x7fffffffe6d8 "\335\351\377\377\377\177"
#4  0x000055555561b8b2 in main (argc=1, argv=0x7fffffffe6c8) at src/main.c:180
        entries =
            {{long_name = 0x5555556455ab "version", short_name = 118 'v', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x5555556c6d60 <version>, description = 0x5555556455b3 "Show version information", arg_description = 0x0}, {long_name = 0x5555556455cc "account", short_name = 97 'a', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x5555556c6d78 <account_name>, description = 0x5555556455d8 "Auto connect to an account on startup", arg_description = 0x0}, {long_name = 0x5555556455fe "log", short_name = 108 'l', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x5555556c6d68 <log>, description = 0x555555645608 "Set logging levels, DEBUG, INFO (default), WARN, ERROR", arg_description = 0x55555564563f "LEVEL"}, {long_name = 0x555555645645 "config", short_name = 99 'c', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x5555556c6d80 <config_file>, description = 0x555555645650 "Use an alternative configuration file", arg_description = 0x0}, {long_name = 0x555555645676 "logfile", short_name = 102 'f', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x5555556c6d70 <log_file>, description = 0x55555564567e "Specify log filename", arg_description = 0x0}, {long_name = 0x555555645693 "theme", short_name = 116 't', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x5555556c6d88 <theme_name>, description = 0x555555645699 "Specify theme name", arg_description = 0x0}, {long_name = 0x0, short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x0, description = 0x0, arg_description = 0x0}}
        error = 0x0
        context = 0x7ffff7b28640

@jubalh jubalh added this to the 0.9.1 milestone Jun 10, 2020
@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

Is XDG_CONFIG_HOME set on your system? If yes, to what?
Is HOME set on your system? If yes, to what?
Does $HOME/.config exist?

@gjabell
Copy link
Author

gjabell commented Jun 10, 2020

HOME: /home/gjabell
XDG_CONFIG_HOME: /home/gjabell/.config
$HOME/.config does exist

@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

Thank you for checking. Do you know how to use gdb?

gdb ./profanity
b files_create_directories
r

Then use n to step to the next line or s to step into a function.

Are you in our MUC? You could ping me there and we could do it together.

@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

I tried with and without the XDG variables set. Works both times for me.

@gjabell
Copy link
Author

gjabell commented Jun 10, 2020

Hmm...with XDG_CONFIG_HOME set, it looks like it correctly reads the config directory in _files_get_xdg_config_home, but the returned strdup yields an invalid pointer:

In _files_get_xdg_config_home:

(gdb) p xdg_config_home
$1 = (gchar *) 0x7fffffffefa6 "/home/gjabell/.config"

In files_create_directories:

(gdb) p xdg_config
$1 = (gchar *) 0xfffffffff7b287a0 <error: Cannot access memory at address 0xfffffffff7b287a0>

Which OS are you running? I suspect this is an issue with Alpine.

@DebXWoody
Copy link
Contributor

Which Version of glibc?

@gjabell
Copy link
Author

gjabell commented Jun 10, 2020

None :P
Alpine uses Musl

@DebXWoody
Copy link
Contributor

Debian GNU/Linux is a nice OS :-D ;-)

@DebXWoody
Copy link
Contributor

Maybe the feature_test_macros?

"If no feature test macros are defined, musl's headers operate in "default features" mode, exposing the equivalent of the _BSD_SOURCE option below."
(https://musl.libc.org/doc/1.1.24/manual.html)

@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

Alpine uses Musl

Maybe this is the issue. Do you know Alpine folks who might have encountered this? I heard that in the past there were similar things if I remember correctly. Maybe some Alpine maintainer knows more?

@gjabell
Copy link
Author

gjabell commented Jun 10, 2020

I'll check in the IRC channel; what's weird is that it works fine with version 0.8.1 (running it as we speak), but the code for loading the config directory hasn't changed between those versions.

@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

Yeah a very weird bug.

@jubalh
Copy link
Member

jubalh commented Jun 10, 2020

We changed configure.ac to compile with c99, not sure this could affect it?
And the code that causes this could also be written in another way. I would like to send you a patch (probably tomorrow) to find out whether this also causes the problem. Just out of curiosity.

@gjabell
Copy link
Author

gjabell commented Jun 10, 2020

Your guess is as good as mine :P
That would be great, no hurry though :-) I really appreciate all the help!

@jubalh
Copy link
Member

jubalh commented Jun 11, 2020

@gjabell would you mind creating a PR for our website so that we have a one liner to install the dependencies on Alpine?

For example:
https://github.com/profanity-im/profanity-im.github.io/blob/master/guide/latest/build.html
https://profanity-im.github.io/guide/latest/build.html

@jubalh jubalh removed this from the 0.9.1 milestone Jun 11, 2020
@jubalh
Copy link
Member

jubalh commented Jun 11, 2020

Removed this from milestone 0.9.1 since I think this is Alpine specific and I wanted to get the latest changes out. We can still do a 0.9.2 if we fix this soon :)

@gjabell
Copy link
Author

gjabell commented Jun 11, 2020

So I did some more digging with git bisect and it looks like it's probably related to the C99 change - profanity builds and runs fine up until 26cda6b, and then fails to build with errors until tag 0.9.0 at which point it builds with warnings but fails to run.

@jubalh
Copy link
Member

jubalh commented Jun 11, 2020

@gjabell can you for now patch the Alpine package to remove #1351 ?

Does it work then?

@pasis any idea why c99 with musl can cause this?

The PR mentioned above was only created because of our use of "\u200E".
This is the commit that added it 87f9bac

It was added due to some messed up UI reported here: #1220

I'm not sure if it was the best solution. It might mean that there are hundreds of UTF-8 characters that we need to filter out so as to not mess up the UI.
I also thought about using utf8proc.

It was an issue where I did not know much but wanted to fix it for the users. Maybe now is a good time to review it. Let's hear your thoughts :-)

@gjabell
Copy link
Author

gjabell commented Jun 11, 2020

@jubalh That seems to do the trick! I'll do some research and see if I can't find why enable c99 causes an issue with Musl.

jubalh added a commit that referenced this issue Jun 12, 2020
Found this when looking to fix bug #1357
Not sure if it is related.

man 3 getenv sais:
```
As  typically implemented, getenv() returns a pointer to a string within
the environment list.  The caller must take  care  not  to  modify  this
string, since that would change the environment of the process.
```
@jubalh
Copy link
Member

jubalh commented Jun 12, 2020

@gjabell can you try whether it works with c99 if you apply https://github.com/profanity-im/profanity/commit/f1141932fc45fa4bcc87984241b524381c0ab2b3.patch ?

@gjabell
Copy link
Author

gjabell commented Jun 12, 2020

@jubalh Looks like the issue persists, unfortunately :/

jubalh added a commit that referenced this issue Jun 12, 2020
98c38dc
sets C99 as standard.

strdup() is not part of C99.

For now set `-D_POSIX_C_SOURCE=200809L` macro to have strdup() in C99.
Using `gnu99` instead would be another option.

We should take more care to use glib functions whenever possible.

Regards #1357
@jubalh
Copy link
Member

jubalh commented Jun 12, 2020

@jubalh jubalh added this to the 0.9.2 milestone Jun 12, 2020
@gjabell
Copy link
Author

gjabell commented Jun 12, 2020

That seems to have fixed it! 🎉

Thanks so much for your help @jubalh!

@jubalh
Copy link
Member

jubalh commented Jun 12, 2020

Cool!
It will be in 0.9.2 (coming the next days/week).

So it was just that alpine/musl were more pedantic than what we tried so far, and not "alpines fault" :)

@jubalh jubalh closed this as completed Jun 12, 2020
@gjabell
Copy link
Author

gjabell commented Jun 12, 2020

Great :) I'll go ahead and make an Alpine release to 0.9.1 with that patch and the keep an eye out for 0.9.2

jubalh added a commit that referenced this issue Jun 13, 2020
With recent changes to c99 and -D_POSIX_C_SOURCE=200809L we get the following:

openSUSE TW CI sais:
```
Now you can run `make' to build profanity

In file included from /usr/include/python2.7/Python.h:8,

                 from src/plugins/python_plugins.c:37:

/usr/include/python2.7/pyconfig.h:1226: error: "_POSIX_C_SOURCE" redefined [-Werror]

 1226 | #define _POSIX_C_SOURCE 200112L

      |

<command-line>: note: this is the location of the previous definition

In file included from /usr/include/python2.7/Python.h:8,

                 from src/plugins/python_api.c:37:

/usr/include/python2.7/pyconfig.h:1226: error: "_POSIX_C_SOURCE" redefined [-Werror]

 1226 | #define _POSIX_C_SOURCE 200112L

      |

<command-line>: note: this is the location of the previous definition

cc1: all warnings being treated as errors
```

OpenBSD CI sais:
```
cc1: warnings being treated as errors
src/database.c: In function 'log_database_get_previous_chat':
src/database.c:226: warning: implicit declaration of function 'asprintf'
gmake[1]: *** [Makefile:1924: src/database.o] Error 1
gmake[1]: Leaving directory '/home/build/profanity'
gmake: *** [Makefile:1211: all] Error 2
```

Let us use gnu99. Has been proposed before already and is fine.

Regards #1357
Regards #1351
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants