Search in sources :

Example 31 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangConnector connectorNode) {
    BSymbol connectorSymbol = connectorNode.symbol;
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
    attachTaintTableBasedOnAnnotations(connectorNode);
    connectorNode.varDefs.forEach(var -> var.accept(this));
    analyzeNode(connectorNode.initFunction, connectorEnv);
    analyzeNode(connectorNode.initAction, connectorEnv);
    connectorNode.actions.forEach(action -> analyzeNode(action, connectorEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 32 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangXMLElementLiteral xmlElementLiteral) {
    SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
    // Visit in-line namespace declarations
    boolean inLineNamespaceTainted = false;
    for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
        if (attribute.name.getKind() == NodeKind.XML_QNAME && ((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            attribute.accept(this);
            attribute.symbol.tainted = getObservedTaintedStatus();
            if (attribute.symbol.tainted) {
                inLineNamespaceTainted = true;
            }
        }
    }
    // Visit attributes.
    boolean attributesTainted = false;
    for (BLangXMLAttribute attribute : xmlElementLiteral.attributes) {
        if (attribute.name.getKind() == NodeKind.XML_QNAME && !((BLangXMLQName) attribute.name).prefix.value.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            attribute.accept(this);
            attribute.symbol.tainted = getObservedTaintedStatus();
            if (attribute.symbol.tainted) {
                attributesTainted = true;
            }
        }
    }
    // Visit the tag names
    xmlElementLiteral.startTagName.accept(this);
    boolean startTagTaintedStatus = getObservedTaintedStatus();
    boolean endTagTaintedStatus = false;
    if (xmlElementLiteral.endTagName != null) {
        xmlElementLiteral.endTagName.accept(this);
        endTagTaintedStatus = getObservedTaintedStatus();
    }
    boolean tagNamesTainted = startTagTaintedStatus || endTagTaintedStatus;
    // Visit the children
    boolean childrenTainted = false;
    for (BLangExpression expr : xmlElementLiteral.children) {
        expr.accept(this);
        if (getObservedTaintedStatus()) {
            childrenTainted = true;
        }
    }
    setTaintedStatusList(inLineNamespaceTainted || attributesTainted || tagNamesTainted || childrenTainted);
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 33 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv 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));
    }
}
Also used : ArrayList(java.util.ArrayList) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 34 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangExpressionStmt exprStmtNode) {
    SymbolEnv stmtEnv = new SymbolEnv(exprStmtNode, this.env.scope);
    this.env.copyTo(stmtEnv);
    analyzeNode(exprStmtNode.expr, stmtEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 35 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangWorker workerNode) {
    SymbolEnv workerEnv = SymbolEnv.createWorkerEnv(workerNode, this.env);
    analyzeNode(workerNode.body, workerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)125 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)47 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)30 Name (org.wso2.ballerinalang.compiler.util.Name)26 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)25 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)24 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)20 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)20 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)19 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)18 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)17 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)17 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)17 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)17 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17