From 183298ba50e6a95919b6ec850292e43d6d64900b Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 18 Jan 2017 17:28:19 +0000 Subject: [PATCH] MCOL-477 Add validation to alter autoincrement If the data isn't validated and someone gives bad input it could cause corruption. This validates the input. --- dbcon/ddlpackageproc/altertableprocessor.cpp | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/dbcon/ddlpackageproc/altertableprocessor.cpp b/dbcon/ddlpackageproc/altertableprocessor.cpp index b4cdd1a4c..d73c3a624 100644 --- a/dbcon/ddlpackageproc/altertableprocessor.cpp +++ b/dbcon/ddlpackageproc/altertableprocessor.cpp @@ -1854,6 +1854,68 @@ void AlterTableProcessor::tableComment(uint32_t sessionID, execplan::CalpontSyst throw std::runtime_error("Table does not have an autoincrement column"); } int32_t oid = systemCatalogPtr->autoColumOid(tableName); + + CalpontSystemCatalog::ColType type = systemCatalogPtr->colType(oid); + + bool validated = true; + bool negative = false; + + switch (type.colDataType) + { + case CalpontSystemCatalog::BIGINT: + if (static_cast(nextVal) > MAX_BIGINT) + validated = false; + if (static_cast(nextVal) < 1) + negative = true; + break; + case CalpontSystemCatalog::UBIGINT: + if (nextVal > MAX_UBIGINT) + validated = false; + break; + case CalpontSystemCatalog::INT: + case CalpontSystemCatalog::MEDINT: + if (static_cast(nextVal) > MAX_INT) + validated = false; + if (static_cast(nextVal) < 1) + negative = true; + break; + case CalpontSystemCatalog::UINT: + case CalpontSystemCatalog::UMEDINT: + if (nextVal > MAX_UINT) + validated = false; + break; + case CalpontSystemCatalog::SMALLINT: + if (static_cast(nextVal) > MAX_SMALLINT) + validated = false; + if (static_cast(nextVal) < 1) + negative = true; + break; + case CalpontSystemCatalog::USMALLINT: + if (nextVal > MAX_USMALLINT) + validated = false; + break; + case CalpontSystemCatalog::TINYINT: + if (static_cast(nextVal) > MAX_TINYINT) + validated = false; + if (static_cast(nextVal) < 1) + negative = true; + break; + case CalpontSystemCatalog::UTINYINT: + if (nextVal > MAX_UTINYINT) + validated = false; + break; + default: + break; + } + if (!validated) + { + throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_INVALID_START_VALUE)); + } + if (negative) + { + throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_NEGATIVE_STARTVALUE)); + } + fDbrm->resetAISequence(oid, nextVal); ByteStream bs; bs.restart();