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

fix the condition of SVFIR::isValidPointer #1003

Merged
merged 2 commits into from
Jan 24, 2023

Conversation

sinotca529
Copy link
Contributor

Fix the issue #1002

@yuleisui
Copy link
Collaborator

It looks this will affect quite a few other cases. Would be good to dig it a bit or make it just for DDA.

@sinotca529
Copy link
Contributor Author

Observation of errors in the regression test and testing with a hand-made code revealed that errors occur when passing string literals to puts/printf.

This is the hand-made code that causes an error:

#include <stdio.h>
int main(void) {
    puts("foo");
    return 0;
}

The error occured when SVF tries to analyze the 0th arg of puts.
Because puts is a declaration and SVFIRBuilder::handleExtCall does not make call edges from actual parameters to formal parameters, the 0th arg of puts has no incoming edges and no outcoming edges.
So, it satisfies SVFIR::isValidPointer wrongly.

To avoid this exception, I updated the condition of SVFIR::isValidPointer as:

/*
 * If this is a dummy node or node does not have incoming edges and outcoming edges we assume it is not a pointer here.
 * However, if it is a pointer and it is an argument of a function definition, we assume it is a pointer here.
 */
bool SVFIR::isValidPointer(NodeID nodeId) const
{
    SVFVar* node = pag->getGNode(nodeId);

    if (node->hasValue() && node->isPointer())
    {
        if(const SVFArgument* arg = SVFUtil::dyn_cast<SVFArgument>(node->getValue()))
        {
            if (!(arg->getParent()->isDeclaration()))
                return true;
        }
    }

    if ((node->getInEdges().empty() && node->getOutEdges().empty()))
        return false;
    return node->isPointer();
}

@codecov
Copy link

codecov bot commented Jan 24, 2023

Codecov Report

Merging #1003 (1046275) into master (17193ff) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1003   +/-   ##
=======================================
  Coverage   63.71%   63.71%           
=======================================
  Files         219      219           
  Lines       22020    22023    +3     
=======================================
+ Hits        14030    14033    +3     
  Misses       7990     7990           
Impacted Files Coverage Δ
svf/lib/SVFIR/SVFIR.cpp 79.56% <100.00%> (+0.22%) ⬆️

@yuleisui yuleisui merged commit 831f0e8 into SVF-tools:master Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants