From 9bb6befa25576a360a0987ab14a8b9b55dfd0c34 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 1 Oct 2015 09:06:27 +0900 Subject: [PATCH] Sanity check 'conninfo' parameter Catch errors early, it makes everyone's life easier. --- config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config.c b/config.c index 88265a96..980a1759 100644 --- a/config.c +++ b/config.c @@ -111,6 +111,10 @@ parse_config(t_configuration_options *options) char name[MAXLEN]; char value[MAXLEN]; + /* For sanity-checking provided conninfo string */ + PQconninfoOption *conninfo_options; + char *conninfo_errmsg = NULL; + fp = fopen(config_file_path, "r"); /* @@ -310,6 +314,18 @@ parse_config(t_configuration_options *options) exit(ERR_BAD_CONFIG); } + /* Sanity check the provided conninfo string + * + * NOTE: this verifies the string format and checks for valid options + * but does not sanity check values + */ + conninfo_options = PQconninfoParse(options->conninfo, &conninfo_errmsg); + if (conninfo_options == NULL) + { + log_err(_("Parameter 'conninfo' is invalid: %s"), conninfo_errmsg); + exit(ERR_BAD_CONFIG); + } + /* The following checks are for valid parameter values */ if (options->master_response_timeout <= 0) {