Add exception handling for the retrieve method and do explicit checks for limit and skip
@@ -78,6 +78,7 @@ Document document; // Default template parameter uses UTF8 and MemoryPoolAlloca
SQLBuffer sql;
SQLBuffer jsonConstraints; // Extra constraints to add to where clause
+ try {
if (condition.empty())
{
sql.append("SELECT * FROM foglamp.");
@@ -228,6 +229,9 @@ SQLBuffer jsonConstraints; // Extra constraints to add to where clause
}
PQclear(res);
return false;
+ } catch (exception e) {
+ raiseError("retrieve", "Internal error: %s", e.what());
+ }
}
/**
@@ -1379,14 +1383,29 @@ bool Connection::jsonModifiers(const Value& payload, SQLBuffer& sql)
if (payload.HasMember("skip"))
{
+ if (!payload["skip"].IsInt())
+ {
+ raiseError("skip", "Skip must be specfied as an integer");
+ return false;
+ }
sql.append(" OFFSET ");
sql.append(payload["skip"].GetInt());
}
if (payload.HasMember("limit"))
{
+ if (!payload["limit"].IsInt())
+ {
+ raiseError("limit", "Limit must be specfied as an integer");
+ return false;
+ }
sql.append(" LIMIT ");
+ try {
sql.append(payload["limit"].GetInt());
+ } catch (exception e) {
+ raiseError("limit", "Bad value for limit parameter: %s", e.what());
+ return false;
+ }
}
return true;
}
