From fec5a1577afe3a138ef54ad18920aa29386de0cb Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Mon, 17 May 2021 15:26:40 +0530 Subject: [PATCH v1] Tighten up batch_size, fetch_size options against non-numeric values It looks like the values such as '123.456', '789.123' '100$%$#$#', '9,223,372,' are accepted and treated as valid integers for postgres_fdw options batch_size and fetch_size. Whereas this is not the case with fdw_startup_cost and fdw_tuple_cost options for which an error is thrown. This patch fixes this with passing endptr to strtol. --- contrib/postgres_fdw/option.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index 672b55a808..d4044406a7 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -137,9 +137,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS) else if (strcmp(def->defname, "fetch_size") == 0) { int fetch_size; + char *endp; - fetch_size = strtol(defGetString(def), NULL, 10); - if (fetch_size <= 0) + fetch_size = strtol(defGetString(def), &endp, 10); + if (*endp || fetch_size <= 0) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("%s requires a non-negative integer value", @@ -148,9 +149,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS) else if (strcmp(def->defname, "batch_size") == 0) { int batch_size; + char *endp; - batch_size = strtol(defGetString(def), NULL, 10); - if (batch_size <= 0) + batch_size = strtol(defGetString(def), &endp, 10); + if (*endp || batch_size <= 0) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("%s requires a non-negative integer value", -- 2.25.1