]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Assert that wrapper_handler()'s argument is within expected range.
authorNathan Bossart <nathan@postgresql.org>
Fri, 7 Mar 2025 21:23:09 +0000 (15:23 -0600)
committerNathan Bossart <nathan@postgresql.org>
Fri, 7 Mar 2025 21:23:09 +0000 (15:23 -0600)
pqsignal() already does a similar check, but strange Valgrind
reports have us wondering if wrapper_handler() is somehow getting
called with an invalid signal number.

Reported-by: Tomas Vondra <tomas@vondra.me>
Suggested-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/ace01111-f9ac-4f61-b1b1-8e9379415444%40vondra.me
Backpatch-through: 17

src/port/pqsignal.c

index bbd28da0805316aadf74d16c1f30375efe28883c..9dadce8357dca0b77d5df4f03f722176008831a8 100644 (file)
@@ -87,6 +87,9 @@ wrapper_handler(SIGNAL_ARGS)
 {
        int                     save_errno = errno;
 
+       Assert(postgres_signal_arg > 0);
+       Assert(postgres_signal_arg < PG_NSIG);
+
 #ifndef FRONTEND
 
        /*
@@ -139,6 +142,7 @@ pqsignal(int signo, pqsigfunc func)
        pqsigfunc       ret;
 #endif
 
+       Assert(signo > 0);
        Assert(signo < PG_NSIG);
 
        if (func != SIG_IGN && func != SIG_DFL)