]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: init: report invalid characters in debug description strings
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Apr 2025 17:00:01 +0000 (19:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Apr 2025 17:02:13 +0000 (19:02 +0200)
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.

src/debug.c

index d7ac90f478903d61225204462513199d4a5cb456..c991f96cb154d1d232dd26fb8e8b08da9a8d0e1b 100644 (file)
@@ -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);