Merge pull request #636 from citusdata/fix/634_null_check_sqlStateString

Add null check to SqlStateMatchesCategory()
pull/639/head
Andres Freund 2016-07-01 12:37:06 -07:00 committed by GitHub
commit 0b6819f773
1 changed files with 15 additions and 7 deletions

View File

@ -192,19 +192,27 @@ PurgeConnection(PGconn *connection)
/* /*
* SqlStateMatchesCategory returns true if the given sql state is in the given * SqlStateMatchesCategory returns true if the given sql state (which may be
* error category. Note that we use ERRCODE_TO_CATEGORY macro to determine error * NULL if unknown) is in the given error category. Note that we use
* category of the sql state and expect the caller to use the same macro for the * ERRCODE_TO_CATEGORY macro to determine error category of the sql state and
* error category. * expect the caller to use the same macro for the error category.
*/ */
bool bool
SqlStateMatchesCategory(char *sqlStateString, int category) SqlStateMatchesCategory(char *sqlStateString, int category)
{ {
bool sqlStateMatchesCategory = false; bool sqlStateMatchesCategory = false;
int sqlState = MAKE_SQLSTATE(sqlStateString[0], sqlStateString[1], sqlStateString[2], int sqlState = 0;
sqlStateString[3], sqlStateString[4]); int sqlStateCategory = 0;
int sqlStateCategory = ERRCODE_TO_CATEGORY(sqlState); if (sqlStateString == NULL)
{
return false;
}
sqlState = MAKE_SQLSTATE(sqlStateString[0], sqlStateString[1], sqlStateString[2],
sqlStateString[3], sqlStateString[4]);
sqlStateCategory = ERRCODE_TO_CATEGORY(sqlState);
if (sqlStateCategory == category) if (sqlStateCategory == category)
{ {
sqlStateMatchesCategory = true; sqlStateMatchesCategory = true;