Re: [PATCH] Fix segfault calling PQflush on invalid connection - Mailing list pgsql-bugs

From Tom Lane
Subject Re: [PATCH] Fix segfault calling PQflush on invalid connection
Date
Msg-id 819197.1660527847@sss.pgh.pa.us
Whole thread Raw
In response to [PATCH] Fix segfault calling PQflush on invalid connection  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Responses Re: [PATCH] Fix segfault calling PQflush on invalid connection
List pgsql-bugs
Daniele Varrazzo <daniele.varrazzo@gmail.com> writes:
> PQflush calls pqFlush, which performs struct access to the connection
> without checking if it's valid, resulting in a segfault if called with
> a null pointer.

> Please find attached a patch adding a guard to PQflush().

Seems reasonable, but this tickled a thought that's been in my
hindbrain for awhile: just checking for a null pointer is not
much of a check for being passed a valid PGconn pointer.  Should
we add a magic number to struct PGconn, and modify all libpq's
entry points along the lines of

    if (!conn || conn->magic != PGCONN_MAGIC)
        return failure;

I'm honestly not entirely sure if this is worth the trouble;
I've not heard of many application bugs that this would've caught.
But the lack of any such check does seem like it's not up to
modern standards.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Daniele Varrazzo
Date:
Subject: [PATCH] Fix segfault calling PQflush on invalid connection
Next
From: "巨鲸"
Date:
Subject: Re: BUG #17580: use pg_terminate_backend to terminate a wal sender process may wait a long time