Disable abort in log_assert in libsystemd/libudev (#39307)
See the second commit for details. I think we might want to apply the same treatment to nss and pam modules. Asserting in such "plugin code" seems iffy. But this PR doesn't change those in any way.
This commit is contained in:
+2
-29
@@ -4,40 +4,13 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "env-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "log.h"
|
||||
|
||||
static bool assert_return_is_critical = BUILD_MODE_DEVELOPER;
|
||||
|
||||
/* Akin to glibc's __abort_msg; which is private and we hence cannot
|
||||
* use here. */
|
||||
static char *log_abort_msg = NULL;
|
||||
|
||||
void log_set_assert_return_is_critical(bool b) {
|
||||
assert_return_is_critical = b;
|
||||
}
|
||||
|
||||
void log_set_assert_return_is_critical_from_env(void) {
|
||||
static int cached = INT_MIN;
|
||||
int r;
|
||||
|
||||
if (cached == INT_MIN) {
|
||||
r = secure_getenv_bool("SYSTEMD_ASSERT_RETURN_IS_CRITICAL");
|
||||
if (r < 0 && r != -ENXIO)
|
||||
log_debug_errno(r, "Failed to parse $SYSTEMD_ASSERT_RETURN_IS_CRITICAL, ignoring: %m");
|
||||
|
||||
cached = r;
|
||||
}
|
||||
|
||||
if (cached >= 0)
|
||||
log_set_assert_return_is_critical(cached);
|
||||
}
|
||||
|
||||
bool log_get_assert_return_is_critical(void) {
|
||||
return assert_return_is_critical;
|
||||
}
|
||||
|
||||
static void log_assert(
|
||||
int level,
|
||||
const char *text,
|
||||
@@ -73,8 +46,8 @@ _noreturn_ void log_assert_failed_unreachable(const char *file, int line, const
|
||||
}
|
||||
|
||||
void log_assert_failed_return(const char *text, const char *file, int line, const char *func) {
|
||||
|
||||
if (assert_return_is_critical)
|
||||
/* log_get_assert_return_is_critical is a weak symbol. It may be NULL. */
|
||||
if (log_get_assert_return_is_critical && log_get_assert_return_is_critical())
|
||||
log_assert_failed(text, file, line, func);
|
||||
|
||||
PROTECT_ERRNO;
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
|
||||
/* Logging for various assertions */
|
||||
|
||||
void log_set_assert_return_is_critical(bool b);
|
||||
void log_set_assert_return_is_critical_from_env(void);
|
||||
bool log_get_assert_return_is_critical(void) _pure_;
|
||||
bool log_get_assert_return_is_critical(void) _weak_ _pure_;
|
||||
|
||||
void log_assert_failed_return(const char *text, const char *file, int line, const char *func);
|
||||
|
||||
|
||||
+1
-1
@@ -22,6 +22,6 @@ static struct mempool pool_name = { \
|
||||
.at_least = alloc_at_least, \
|
||||
}
|
||||
|
||||
__attribute__((weak)) bool mempool_enabled(void);
|
||||
bool mempool_enabled(void) _weak_ _pure_;
|
||||
|
||||
void mempool_trim(struct mempool *mp);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "log-assert-critical.h"
|
||||
|
||||
/* The entry point into the fuzzer */
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "env-util.h"
|
||||
#include "log.h"
|
||||
#include "log-assert-critical.h"
|
||||
|
||||
static bool assert_return_is_critical = BUILD_MODE_DEVELOPER;
|
||||
|
||||
void log_set_assert_return_is_critical(bool b) {
|
||||
assert_return_is_critical = b;
|
||||
}
|
||||
|
||||
void log_set_assert_return_is_critical_from_env(void) {
|
||||
static int cached = INT_MIN;
|
||||
int r;
|
||||
|
||||
if (cached == INT_MIN) {
|
||||
r = secure_getenv_bool("SYSTEMD_ASSERT_RETURN_IS_CRITICAL");
|
||||
if (r < 0 && r != -ENXIO)
|
||||
log_debug_errno(r, "Failed to parse $SYSTEMD_ASSERT_RETURN_IS_CRITICAL, ignoring: %m");
|
||||
|
||||
cached = r;
|
||||
}
|
||||
|
||||
if (cached >= 0)
|
||||
log_set_assert_return_is_critical(cached);
|
||||
}
|
||||
|
||||
bool log_get_assert_return_is_critical(void) {
|
||||
return assert_return_is_critical;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "basic-forward.h"
|
||||
|
||||
void log_set_assert_return_is_critical(bool b);
|
||||
void log_set_assert_return_is_critical_from_env(void);
|
||||
@@ -119,6 +119,7 @@ shared_sources = files(
|
||||
'libmount-util.c',
|
||||
'local-addresses.c',
|
||||
'locale-setup.c',
|
||||
'log-assert-critical.c',
|
||||
'logs-show.c',
|
||||
'loop-util.c',
|
||||
'loopback-setup.c',
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "log.h"
|
||||
#include "log-assert-critical.h"
|
||||
#include "nss-util.h"
|
||||
|
||||
sd_json_dispatch_flags_t nss_json_dispatch_flags = SD_JSON_ALLOW_EXTENSIONS;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "errno-util.h"
|
||||
#include "shared-forward.h"
|
||||
#include "log.h"
|
||||
#include "log-assert-critical.h"
|
||||
#include "static-destruct.h"
|
||||
#include "signal-util.h"
|
||||
#include "stdio-util.h"
|
||||
|
||||
Reference in New Issue
Block a user