mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 22:43:03 +01:00
Fix #7670 - Cursor name can duplicate parameter and variable names in procedures and functions.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d10d43ecde
commit
00ad2af2fa
@ -1664,15 +1664,15 @@ DdlNode* CreateAlterFunctionNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
|
|||||||
{
|
{
|
||||||
dsqlScratch->flags |= (DsqlCompilerScratch::FLAG_BLOCK | DsqlCompilerScratch::FLAG_FUNCTION);
|
dsqlScratch->flags |= (DsqlCompilerScratch::FLAG_BLOCK | DsqlCompilerScratch::FLAG_FUNCTION);
|
||||||
|
|
||||||
// check for duplicated parameter names
|
// check for duplicated parameters and declaration names
|
||||||
|
|
||||||
SortedArray<MetaName> names;
|
StrArray names;
|
||||||
|
|
||||||
for (FB_SIZE_T i = 0; i < parameters.getCount(); ++i)
|
for (FB_SIZE_T i = 0; i < parameters.getCount(); ++i)
|
||||||
{
|
{
|
||||||
const ParameterClause* const parameter = parameters[i];
|
const ParameterClause* const parameter = parameters[i];
|
||||||
|
|
||||||
if (names.exist(parameter->name))
|
if (names.exist(parameter->name.c_str()))
|
||||||
{
|
{
|
||||||
status_exception::raise(
|
status_exception::raise(
|
||||||
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
||||||
@ -1680,34 +1680,10 @@ DdlNode* CreateAlterFunctionNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parameter->name.hasData()) // legacy UDFs has unnamed parameters
|
if (parameter->name.hasData()) // legacy UDFs has unnamed parameters
|
||||||
names.add(parameter->name);
|
names.add(parameter->name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompoundStmtNode* variables = localDeclList;
|
PASS1_check_unique_fields_names(names, localDeclList);
|
||||||
if (variables)
|
|
||||||
{
|
|
||||||
// insure that variable names do not duplicate parameter names
|
|
||||||
|
|
||||||
const NestConst<StmtNode>* ptr = variables->statements.begin();
|
|
||||||
for (const NestConst<StmtNode>* const end = variables->statements.end(); ptr != end; ++ptr)
|
|
||||||
{
|
|
||||||
const DeclareVariableNode* varNode = nodeAs<DeclareVariableNode>(*ptr);
|
|
||||||
|
|
||||||
if (varNode)
|
|
||||||
{
|
|
||||||
const dsql_fld* field = varNode->dsqlDef->type;
|
|
||||||
DEV_BLKCHK(field, dsql_type_fld);
|
|
||||||
|
|
||||||
if (names.exist(field->fld_name))
|
|
||||||
{
|
|
||||||
status_exception::raise(
|
|
||||||
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
|
||||||
Arg::Gds(isc_dsql_var_conflict) <<
|
|
||||||
Arg::Str(field->fld_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
source.ltrim("\n\r\t ");
|
source.ltrim("\n\r\t ");
|
||||||
|
|
||||||
@ -2659,63 +2635,39 @@ DdlNode* CreateAlterProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
|
|||||||
{
|
{
|
||||||
dsqlScratch->flags |= (DsqlCompilerScratch::FLAG_BLOCK | DsqlCompilerScratch::FLAG_PROCEDURE);
|
dsqlScratch->flags |= (DsqlCompilerScratch::FLAG_BLOCK | DsqlCompilerScratch::FLAG_PROCEDURE);
|
||||||
|
|
||||||
// check for duplicated parameter names
|
// check for duplicated parameters and declaration names
|
||||||
|
|
||||||
SortedArray<MetaName> names;
|
StrArray names;
|
||||||
|
|
||||||
for (FB_SIZE_T i = 0; i < parameters.getCount(); ++i)
|
for (FB_SIZE_T i = 0; i < parameters.getCount(); ++i)
|
||||||
{
|
{
|
||||||
const ParameterClause* const parameter = parameters[i];
|
const ParameterClause* const parameter = parameters[i];
|
||||||
|
|
||||||
if (names.exist(parameter->name))
|
if (names.exist(parameter->name.c_str()))
|
||||||
{
|
{
|
||||||
status_exception::raise(
|
status_exception::raise(
|
||||||
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
||||||
Arg::Gds(isc_dsql_duplicate_spec) << Arg::Str(parameter->name));
|
Arg::Gds(isc_dsql_duplicate_spec) << Arg::Str(parameter->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
names.add(parameter->name);
|
names.add(parameter->name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FB_SIZE_T i = 0; i < returns.getCount(); ++i)
|
for (FB_SIZE_T i = 0; i < returns.getCount(); ++i)
|
||||||
{
|
{
|
||||||
const ParameterClause* const parameter = returns[i];
|
const ParameterClause* const parameter = returns[i];
|
||||||
|
|
||||||
if (names.exist(parameter->name))
|
if (names.exist(parameter->name.c_str()))
|
||||||
{
|
{
|
||||||
status_exception::raise(
|
status_exception::raise(
|
||||||
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
||||||
Arg::Gds(isc_dsql_duplicate_spec) << Arg::Str(parameter->name));
|
Arg::Gds(isc_dsql_duplicate_spec) << Arg::Str(parameter->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
names.add(parameter->name);
|
names.add(parameter->name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompoundStmtNode* variables = localDeclList;
|
PASS1_check_unique_fields_names(names, localDeclList);
|
||||||
if (variables)
|
|
||||||
{
|
|
||||||
// insure that variable names do not duplicate parameter names
|
|
||||||
|
|
||||||
const NestConst<StmtNode>* ptr = variables->statements.begin();
|
|
||||||
for (const NestConst<StmtNode>* const end = variables->statements.end(); ptr != end; ++ptr)
|
|
||||||
{
|
|
||||||
const DeclareVariableNode* varNode = nodeAs<DeclareVariableNode>(*ptr);
|
|
||||||
|
|
||||||
if (varNode)
|
|
||||||
{
|
|
||||||
const dsql_fld* field = varNode->dsqlDef->type;
|
|
||||||
DEV_BLKCHK(field, dsql_type_fld);
|
|
||||||
|
|
||||||
if (names.exist(field->fld_name))
|
|
||||||
{
|
|
||||||
status_exception::raise(
|
|
||||||
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
|
||||||
Arg::Gds(isc_dsql_var_conflict) <<
|
|
||||||
Arg::Str(field->fld_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
source.ltrim("\n\r\t ");
|
source.ltrim("\n\r\t ");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user