use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project ballerina by ballerina-lang.
the class TaintAnalyzer method analyzeReturnTaintedStatus.
private void analyzeReturnTaintedStatus(Map<Integer, TaintRecord> taintTable, BLangInvokableNode invokableNode, SymbolEnv symbolEnv, int paramIndex, int requiredParamCount, int defaultableParamCount) {
resetTaintedStatusOfVariables(invokableNode.requiredParams);
resetTaintedStatusOfVariableDef(invokableNode.defaultableParams);
if (invokableNode.restParam != null) {
resetTaintedStatusOfVariables(Arrays.asList(new BLangVariable[] { invokableNode.restParam }));
}
// Mark the given parameter "tainted".
if (paramIndex != ALL_UNTAINTED_TABLE_ENTRY_INDEX) {
if (paramIndex < requiredParamCount) {
invokableNode.requiredParams.get(paramIndex).symbol.tainted = true;
} else if (paramIndex < requiredParamCount + defaultableParamCount) {
invokableNode.defaultableParams.get(paramIndex - requiredParamCount).var.symbol.tainted = true;
} else {
invokableNode.restParam.symbol.tainted = true;
}
}
analyzeReturnTaintedStatus(invokableNode, symbolEnv);
if (taintErrorSet.size() > 0) {
// When invocation returns an error (due to passing a tainted argument to a sensitive parameter) add current
// error to the table for future reference.
taintTable.put(paramIndex, new TaintRecord(null, new ArrayList<>(taintErrorSet)));
taintErrorSet.clear();
} else if (this.blockedNode == null) {
if (invokableNode.retParams.size() == 0) {
returnTaintedStatusList = new ArrayList<>();
} else {
updatedReturnTaintedStatusBasedOnAnnotations(invokableNode.retParams);
}
taintTable.put(paramIndex, new TaintRecord(returnTaintedStatusList, null));
}
}
use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project ballerina by ballerina-lang.
the class TaintAnalyzer method attachTaintTableBasedOnAnnotations.
private void attachTaintTableBasedOnAnnotations(BLangInvokableNode invokableNode) {
if (invokableNode.symbol.taintTable == null) {
// Extract tainted status of the function by lookint at annotations added to returns.
List<Boolean> retParamsTaintedStatus = new ArrayList<>();
for (BLangVariable retParam : invokableNode.retParams) {
retParamsTaintedStatus.add(hasAnnotation(retParam, ANNOTATION_TAINTED));
}
// Append taint table with tainted status when no parameter is tainted.
Map<Integer, TaintRecord> taintTable = new HashMap<>();
taintTable.put(ALL_UNTAINTED_TABLE_ENTRY_INDEX, new TaintRecord(retParamsTaintedStatus, null));
int requiredParamCount = invokableNode.requiredParams.size();
int defaultableParamCount = invokableNode.defaultableParams.size();
int totalParamCount = requiredParamCount + defaultableParamCount + (invokableNode.restParam == null ? 0 : 1);
if (totalParamCount > 0) {
// Append taint table with tainted status when each parameter is tainted.
for (int paramIndex = 0; paramIndex < totalParamCount; paramIndex++) {
BLangVariable param = getParam(invokableNode, paramIndex, requiredParamCount, defaultableParamCount);
// If parameter is sensitive, test for this parameter being tainted is invalid.
if (hasAnnotation(param, ANNOTATION_SENSITIVE)) {
continue;
}
taintTable.put(paramIndex, new TaintRecord(retParamsTaintedStatus, null));
}
}
invokableNode.symbol.taintTable = taintTable;
}
}
use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project ballerina by ballerina-lang.
the class CodeGenerator method createActionInfoEntry.
private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
BInvokableSymbol actionSymbol = actionNode.symbol;
BInvokableType actionType = (BInvokableType) actionSymbol.type;
// Add action name as an UTFCPEntry to the constant pool
int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
actionInfo.flags = actionSymbol.flags;
// setParameterNames(actionNode, actionInfo);
actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
// Add worker info
this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(actionNode, actionInfo);
// Add action info to the connector info
connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project ballerina by ballerina-lang.
the class CodeGenerator method createFunctionInfoEntry.
/**
* Creates a {@code FunctionInfo} from the given function node in AST.
*
* @param funcNode function node in AST
*/
private void createFunctionInfoEntry(BLangFunction funcNode) {
BInvokableSymbol funcSymbol = funcNode.symbol;
BInvokableType funcType = (BInvokableType) funcSymbol.type;
// Add function name as an UTFCPEntry to the constant pool
int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
funcInfo.flags = funcSymbol.flags;
if (funcNode.receiver != null) {
funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
}
this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(funcNode, funcInfo);
this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangFunction funcNode) {
SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, env);
if (!funcNode.interfaceFunction) {
addReturnIfNotPresent(funcNode);
}
// To preserve endpoint code gen order.
Collections.reverse(funcNode.endpoints);
funcNode.endpoints = rewrite(funcNode.endpoints, fucEnv);
funcNode.body = rewrite(funcNode.body, fucEnv);
funcNode.workers = rewrite(funcNode.workers, fucEnv);
// the struct variable as the first parameter
if (funcNode.receiver != null) {
BInvokableSymbol funcSymbol = funcNode.symbol;
List<BVarSymbol> params = funcSymbol.params;
params.add(0, funcNode.receiver.symbol);
BInvokableType funcType = (BInvokableType) funcSymbol.type;
funcType.paramTypes.add(0, funcNode.receiver.type);
}
result = funcNode;
}
Aggregations