diff options
author | Sven Eden <sven.eden@prydeworx.com> | 2018-11-08 08:13:03 +0100 |
---|---|---|
committer | Sven Eden <sven.eden@prydeworx.com> | 2018-11-08 08:18:48 +0100 |
commit | 2f1ded884ae586639ddb28bc845f78936951307f (patch) | |
tree | c747b2ec5a0c90af681f20c3282f19803b925187 | |
parent | 7f32f9ec687306fb78dd275f0a37d07e397ea5e3 (diff) |
Prep v239.2: Fix handlinjg of program_invocation[_short]_name (#92)
The new detection works, but the consequences weren't enforced
strictly enough.
This lead to SIGABRT on glibc-2.27 systems, when elogind detected
that both variables where different and tried to free them.
But program_invocation_short_name is just a pointer into to long name
memory, so freeing it is leading to a crash.
The resolution is to fully use the new detection: If the used libc
provides both, we do not care about anything any more, as the used
libc is bound to handle everything correctly.
Bug: #92
Closes: #92
Signed-Off-By: Sven Eden <sven.eden@prydeworx.com>
-rw-r--r-- | src/shared/musl_missing.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/shared/musl_missing.c b/src/shared/musl_missing.c index 0f8b4d1ad..f332627fc 100644 --- a/src/shared/musl_missing.c +++ b/src/shared/musl_missing.c @@ -26,14 +26,14 @@ #if HAVE_PROGRAM_INVOCATION_NAME == 0 char *program_invocation_name = NULL; char *program_invocation_short_name = NULL; -#endif // libc does not provide these variables -const char *program_arg_name = NULL; +const char *program_arg_name = NULL; /* Helper */ +#endif // libc does not provide program_invocation_[short_]name #include "musl_missing.h" +#if HAVE_PROGRAM_INVOCATION_NAME == 0 static void elogind_free_program_name(void) { - if (program_invocation_name && (program_invocation_name != program_arg_name) && strlen(program_invocation_name)) program_invocation_name = mfree(program_invocation_name); if (program_invocation_short_name && (program_invocation_short_name != program_arg_name) && strlen(program_invocation_short_name)) @@ -55,8 +55,11 @@ void elogind_set_program_name(const char* pcall) { program_invocation_name = strdup(program_arg_name); if (NULL == program_invocation_short_name) program_invocation_short_name = strdup(basename(program_arg_name)); -#if HAVE_PROGRAM_INVOCATION_NAME == 0 atexit(elogind_free_program_name); -#endif // libc does not provide these variables } +#else +void elogind_set_program_name(const char* pcall) { + assert(pcall && pcall[0]); +} +#endif // libc does not provide program_invocation_[short_]name |