Skip to content

Allow negative paramIndex in ParamFlowRule #549

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

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static boolean passCheck(ResourceWrapper resourceWrapper, /*@Valid*/ ParamFlowRu
}

// Get parameter value. If value is null, then pass.
Object value = args[paramIdx];
Object value = valueAt(args, paramIdx);
if (value == null) {
return true;
}
Expand All @@ -64,6 +64,18 @@ static boolean passCheck(ResourceWrapper resourceWrapper, /*@Valid*/ ParamFlowRu
return passLocalCheck(resourceWrapper, rule, count, value);
}

private static Object valueAt(Object[] args, int paramIdx) {
Object value = null;
if (paramIdx < 0) {
if(-paramIdx <= args.length){
return args[args.length + paramIdx];
}
} else {
value = args[paramIdx];
}
return value;
}

private static boolean passLocalCheck(ResourceWrapper resourceWrapper, ParamFlowRule rule, int count,
Object value) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class ParamFlowRuleUtil {

public static boolean isValidRule(ParamFlowRule rule) {
return rule != null && !StringUtil.isBlank(rule.getResource()) && rule.getCount() >= 0
&& rule.getGrade() >= 0 && rule.getParamIdx() != null && rule.getParamIdx() >= 0 && checkCluster(rule);
&& rule.getGrade() >= 0 && rule.getParamIdx() != null && checkCluster(rule);
}

private static boolean checkCluster(/*@PreChecked*/ ParamFlowRule rule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testCheckValidHotParamRule() {
.setCount(1)
.setParamIdx(-1);
assertFalse(ParamFlowRuleUtil.isValidRule(rule4));
assertFalse(ParamFlowRuleUtil.isValidRule(rule5));
assertTrue(ParamFlowRuleUtil.isValidRule(rule5));

ParamFlowRule goodRule = new ParamFlowRule("abc")
.setCount(10)
Expand Down