8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:03:02 +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

This commit is contained in:
Adriano dos Santos Fernandes 2023-07-08 14:39:47 -03:00
parent d10d43ecde
commit 00ad2af2fa

View File

@ -1664,15 +1664,15 @@ DdlNode* CreateAlterFunctionNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
{
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)
{
const ParameterClause* const parameter = parameters[i];
if (names.exist(parameter->name))
if (names.exist(parameter->name.c_str()))
{
status_exception::raise(
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
names.add(parameter->name);
names.add(parameter->name.c_str());
}
const CompoundStmtNode* variables = 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));
}
}
}
}
PASS1_check_unique_fields_names(names, localDeclList);
source.ltrim("\n\r\t ");
@ -2659,63 +2635,39 @@ DdlNode* CreateAlterProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
{
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)
{
const ParameterClause* const parameter = parameters[i];
if (names.exist(parameter->name))
if (names.exist(parameter->name.c_str()))
{
status_exception::raise(
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
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)
{
const ParameterClause* const parameter = returns[i];
if (names.exist(parameter->name))
if (names.exist(parameter->name.c_str()))
{
status_exception::raise(
Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
Arg::Gds(isc_dsql_duplicate_spec) << Arg::Str(parameter->name));
}
names.add(parameter->name);
names.add(parameter->name.c_str());
}
const CompoundStmtNode* variables = 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));
}
}
}
}
PASS1_check_unique_fields_names(names, localDeclList);
source.ltrim("\n\r\t ");