fix: check range option of alter user

This commit is contained in:
kailixu 2024-06-13 16:36:18 +08:00
parent 8bbdfacca0
commit 1f646713fe
3 changed files with 13 additions and 9 deletions

View File

@ -6605,8 +6605,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
}
static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal,
int64_t maxVal) {
if (val >= 0 && (val < minVal || val > maxVal)) {
int64_t maxVal, bool skipMinus) {
if (skipMinus ? ((val >= 0) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
"Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName,
val, minVal, maxVal);
@ -6616,12 +6616,12 @@ static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const cha
static int32_t checkDbRangeOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t minVal,
int32_t maxVal) {
return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal);
return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, true);
}
static int32_t checkTableRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal,
int64_t maxVal) {
return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal);
return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, true);
}
static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@ -8485,7 +8485,7 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) {
int32_t code = 0;
SCreateUserReq createReq = {0};
if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1))) {
if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false))) {
return code;
}
strcpy(createReq.user, pStmt->userName);
@ -8509,13 +8509,13 @@ static int32_t checkAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) {
int32_t code = 0;
switch (pStmt->alterType) {
case TSDB_ALTER_USER_ENABLE:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1);
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, false);
break;
case TSDB_ALTER_USER_SYSINFO:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1);
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false);
break;
case TSDB_ALTER_USER_CREATEDB:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1);
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, false);
break;
}
return code;

View File

@ -217,14 +217,18 @@ endi
sql_error CREATE USER u100 PASS 'taosdata' SYSINFO -1;
sql_error CREATE USER u101 PASS 'taosdata' SYSINFO 2;
sql_error CREATE USER u102 PASS 'taosdata' SYSINFO 20000;
sql_error CREATE USER u103 PASS 'taosdata' SYSINFO 1000;
sql_error ALTER USER u1 enable -1
sql_error ALTER USER u1 enable 2
sql_error ALTER USER u1 enable 1000
sql_error ALTER USER u1 enable 10000
sql_error ALTER USER u1 sysinfo -1
sql_error ALTER USER u1 sysinfo 2
sql_error ALTER USER u1 sysinfo 1000
sql_error ALTER USER u1 sysinfo -20000
sql_error ALTER USER u1 createdb -1
sql_error ALTER USER u1 createdb 3
sql_error ALTER USER u1 createdb 1000
sql_error ALTER USER u1 createdb 100000
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -514,7 +514,7 @@ class TDTestCase:
def test_alter_user(self):
options = ["enable", "sysinfo", "createdb"]
optionErrVals = [-10000, -128, -1, 2, 127, 10000]
optionErrVals = [-10000, -128, -1, 2, 127, 1000, 10000]
for optionErrVal in optionErrVals:
tdSql.error("create user user_alter pass 'taosdata' sysinfo %d" % optionErrVal)
tdSql.execute("create user user_alter pass 'taosdata'")