Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix issue 55 - False negative in G-9501 when using constant #59

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/com/trivadis/tvdcc/validators/SQLInjection.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.EValidatorRegistrar
import com.trivadis.oracle.plsql.plsql.ConstantDeclaration

class SQLInjection extends PLSQLValidator implements PLSQLCopValidator {
HashMap<Integer, PLSQLCopGuideline> guidelines
Expand Down Expand Up @@ -315,13 +316,22 @@ class SQLInjection extends PLSQLValidator implements PLSQLCopValidator {
}
val declareSection = body.declareSection
if (declareSection !== null) {
val variable = EcoreUtil2.getAllContentsOfType(declareSection, VariableDeclaration).findFirst [
var EObject varOrConst = EcoreUtil2.getAllContentsOfType(declareSection, VariableDeclaration).findFirst [
it.variable.value.equalsIgnoreCase(n.value) && it.getDefault() !== null
]
if (variable !== null) {
for (name : getRelevantSimplExpressionNameValues(variable.getDefault())) {
if (varOrConst !== null) {
for (name : getRelevantSimplExpressionNameValues((varOrConst as VariableDeclaration).getDefault())) {
expressions.put(name.value.toLowerCase, name)
}
} else {
varOrConst = EcoreUtil2.getAllContentsOfType(declareSection, ConstantDeclaration).findFirst [
it.constant.value.equalsIgnoreCase(n.value) && it.getDefault() !== null
]
if (varOrConst !== null) {
for (name : getRelevantSimplExpressionNameValues((varOrConst as ConstantDeclaration).getDefault())) {
expressions.put(name.value.toLowerCase, name)
}
}
}
}
return expressions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,32 @@ class SQLInjectionTest extends AbstractValidatorTest {
Assert.assertEquals(1, issues.size)
}

@Test
def void issue55_using_unasserted_constant_in_execute_immediate() {
val stmt = '''
create or replace procedure exec_sql(in_sql in varchar2) is
co_sql constant varchar2(1000 char) := in_sql;
begin
execute immediate co_sql;
end exec_sql;
/
'''
val issues = stmt.issues
Assert.assertEquals(1, issues.size)
}

@Test
def void issue55_using_asserted_constant_in_execute_immediate() {
val stmt = '''
create or replace procedure exec_sql(in_sql in varchar2) is
co_sql constant varchar2(1000 char) := sys.dbms_assert.noop(in_sql);
begin
execute immediate co_sql;
end exec_sql;
/
'''
val issues = stmt.issues
Assert.assertEquals(0, issues.size)
}

}