Move an assert-only array-bound check to run-time.

When the bound-check fails at run-time, better abort with an error message
rather than trying to user memory we did not allocate.
pull/2561/head
Dimitri Fontaine 2018-12-20 10:21:19 +01:00 committed by Marco Slot
parent 13f4a0ac9f
commit 6a1a2b8458
1 changed files with 7 additions and 2 deletions

View File

@ -100,7 +100,12 @@ ResetConnParams()
void
AddConnParam(const char *keyword, const char *value)
{
Assert((ConnParams.size + 1) < ConnParams.maxSize);
if (ConnParams.size + 1 >= ConnParams.maxSize)
{
/* we expect developers to see that error messages */
ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
errmsg("ConnParams arrays bound check failed")));
}
ConnParams.keywords[ConnParams.size] = strdup(keyword);
ConnParams.values[ConnParams.size] = strdup(value);
@ -263,7 +268,7 @@ GetConnParams(ConnectionHashKey *key, char ***keywords, char ***values,
int paramIndex = 0;
int runtimeParamIndex = 0;
if (ConnParams.size + lengthof(runtimeKeywords) > ConnParams.maxSize)
if (ConnParams.size + lengthof(runtimeKeywords) >= ConnParams.maxSize)
{
/* unexpected, intended as developers rather than users */
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),