From: Willy Tarreau Date: Mon, 14 Apr 2025 17:00:01 +0000 (+0200) Subject: DEBUG: init: report invalid characters in debug description strings X-Git-Tag: v3.2-dev11~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8148c313a787b4df9b8ba379eaba2f417d9cf1e;p=thirdparty%2Fhaproxy.git DEBUG: init: report invalid characters in debug description strings It's easy to leave some trailing \n or even other characters that can mangle the debug output. Let's verify at boot time that the debug sections are clean by checking for chars 0x20 to 0x7e inclusive. This is very simple to do and it managed to find another one in a multi-line message: [WARNING] (23696) : Invalid character 0x0a at position 96 in description string at src/cli.c:2516 _send_status() This way new offending code will be spotted before being committed. --- diff --git a/src/debug.c b/src/debug.c index d7ac90f47..c991f96cb 100644 --- a/src/debug.c +++ b/src/debug.c @@ -2423,6 +2423,7 @@ static int init_debug() { struct sigaction sa; void *callers[1]; + int ret = ERR_NONE; /* calling backtrace() will access libgcc at runtime. We don't want to * do it after the chroot, so let's perform a first call to have it @@ -2442,7 +2443,25 @@ static int init_debug() sa.sa_flags = SA_SIGINFO; sigaction(SIGRTMAX, &sa, NULL); #endif - return ERR_NONE; + +#if !defined(USE_OBSOLETE_LINKER) && ((DEBUG_STRICT > 0) || (DEBUG_COUNTERS > 0)) + if (&__start_dbg_cnt) { + const struct debug_count *ptr; + const char *p; + + for (ptr = &__start_dbg_cnt; ptr < &__stop_dbg_cnt; ptr++) { + for (p = ptr->desc; *p; p++) { + if (*p < 0x20 || *p >= 0x7f) { + ha_warning("Invalid character 0x%02x at position %d in description string at %s:%d %s()\n", + (uchar)*p, (int)(p - ptr->desc), ptr->file, ptr->line, ptr->func); + ret = ERR_WARN; + break; + } + } + } + } +#endif + return ret; } REGISTER_POST_CHECK(init_debug);