Hi I found a nullpointer deref in table-postgres. A patch is attached.
Philipp Ps: thanks gilles for so nice to read code.
From becf40f667f4510e9e964f950b8d78d5c56ee2ba Mon Sep 17 00:00:00 2001 From: Philipp Takacs <phil...@bureaucracy.de> Date: Fri, 2 Feb 2024 12:27:04 +0100 Subject: [PATCH] table-postgres check if errfld is NULL before deref --- extras/tables/table-postgres/table_postgres.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extras/tables/table-postgres/table_postgres.c b/extras/tables/table-postgres/table_postgres.c index e1aa613..2dae3ec 100644 --- a/extras/tables/table-postgres/table_postgres.c +++ b/extras/tables/table-postgres/table_postgres.c @@ -459,7 +459,9 @@ retry: res = PQexecPrepared(config->db, stmt, 0, NULL, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) { errfld = PQresultErrorField(res, PG_DIAG_SQLSTATE); - if (errfld[0] == '0' && errfld[1] == '8') { + /* PQresultErrorField can return NULL if the connection to the server + suddenly closed (e.g. server restart) */ + if (errfld == NULL || (errfld[0] == '0' && errfld[1] == '8')) { log_warnx("warn: trying to reconnect after error: %s", PQerrorMessage(config->db)); PQclear(res); if (config_connect(config)) -- 2.39.2