From c4bd5e9098d98663d711e76cf27aeb8d0ee86650 Mon Sep 17 00:00:00 2001 From: wuyuechuan Date: Sat, 16 Sep 2023 15:04:47 +0800 Subject: [PATCH] validate dblink conn: prevent acess to unknown addresses --- contrib/dblink/dblink.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/dblink/dblink.cpp b/contrib/dblink/dblink.cpp index d1cc54ee6..842ab1bef 100644 --- a/contrib/dblink/dblink.cpp +++ b/contrib/dblink/dblink.cpp @@ -974,10 +974,10 @@ Datum dblink_open(PG_FUNCTION_ARGS) rconn = getConnectionByName(conname); } - linker = rconn->linker; - if (linker == NULL) { + if (rconn == NULL || rconn->linker == NULL) { DBLINK_CONN_NOT_AVAIL; } + linker = rconn->linker; /* Assemble sql */ appendStringInfo(&buf, "DECLARE %s CURSOR FOR %s", curname, sql); @@ -1028,10 +1028,10 @@ Datum dblink_close(PG_FUNCTION_ARGS) rconn = getConnectionByName(conname); } - linker = rconn->linker; - if (linker == NULL) { + if (rconn == NULL || rconn->linker == NULL) { DBLINK_CONN_NOT_AVAIL; } + linker = rconn->linker; appendStringInfo(&buf, "CLOSE %s", curname); @@ -3113,4 +3113,4 @@ static void storeRowInit(storeInfo* sinfo, int nfields, bool first) ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); } -} \ No newline at end of file +}