Skip to content

Commit 6fe9e26

Browse files
Merge pull request #59 from Trivadis/bugfix/issue-55-g-9501-constant
Bugfix issue 55 - False negative in G-9501 when using constant
2 parents c86b496 + 2e129a2 commit 6fe9e26

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/main/java/com/trivadis/tvdcc/validators/SQLInjection.xtend

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import org.eclipse.xtext.EcoreUtil2
4646
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
4747
import org.eclipse.xtext.validation.Check
4848
import org.eclipse.xtext.validation.EValidatorRegistrar
49+
import com.trivadis.oracle.plsql.plsql.ConstantDeclaration
4950

5051
class SQLInjection extends PLSQLValidator implements PLSQLCopValidator {
5152
HashMap<Integer, PLSQLCopGuideline> guidelines
@@ -315,13 +316,22 @@ class SQLInjection extends PLSQLValidator implements PLSQLCopValidator {
315316
}
316317
val declareSection = body.declareSection
317318
if (declareSection !== null) {
318-
val variable = EcoreUtil2.getAllContentsOfType(declareSection, VariableDeclaration).findFirst [
319+
var EObject varOrConst = EcoreUtil2.getAllContentsOfType(declareSection, VariableDeclaration).findFirst [
319320
it.variable.value.equalsIgnoreCase(n.value) && it.getDefault() !== null
320321
]
321-
if (variable !== null) {
322-
for (name : getRelevantSimplExpressionNameValues(variable.getDefault())) {
322+
if (varOrConst !== null) {
323+
for (name : getRelevantSimplExpressionNameValues((varOrConst as VariableDeclaration).getDefault())) {
323324
expressions.put(name.value.toLowerCase, name)
324325
}
326+
} else {
327+
varOrConst = EcoreUtil2.getAllContentsOfType(declareSection, ConstantDeclaration).findFirst [
328+
it.constant.value.equalsIgnoreCase(n.value) && it.getDefault() !== null
329+
]
330+
if (varOrConst !== null) {
331+
for (name : getRelevantSimplExpressionNameValues((varOrConst as ConstantDeclaration).getDefault())) {
332+
expressions.put(name.value.toLowerCase, name)
333+
}
334+
}
325335
}
326336
}
327337
return expressions;

src/test/java/com/trivadis/tvdcc/validators/tests/SQLInjectionTest.xtend

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,32 @@ class SQLInjectionTest extends AbstractValidatorTest {
486486
Assert.assertEquals(1, issues.size)
487487
}
488488

489+
@Test
490+
def void issue55_using_unasserted_constant_in_execute_immediate() {
491+
val stmt = '''
492+
create or replace procedure exec_sql(in_sql in varchar2) is
493+
co_sql constant varchar2(1000 char) := in_sql;
494+
begin
495+
execute immediate co_sql;
496+
end exec_sql;
497+
/
498+
'''
499+
val issues = stmt.issues
500+
Assert.assertEquals(1, issues.size)
501+
}
502+
503+
@Test
504+
def void issue55_using_asserted_constant_in_execute_immediate() {
505+
val stmt = '''
506+
create or replace procedure exec_sql(in_sql in varchar2) is
507+
co_sql constant varchar2(1000 char) := sys.dbms_assert.noop(in_sql);
508+
begin
509+
execute immediate co_sql;
510+
end exec_sql;
511+
/
512+
'''
513+
val issues = stmt.issues
514+
Assert.assertEquals(0, issues.size)
515+
}
516+
489517
}

0 commit comments

Comments
 (0)