Skip to content
\n

So I run this query to the next source code:

\n
using System;\n\nnamespace example2\n{\n\tpublic class Program\n\t{\n\t\tpublic static void Main(string[] args)\n\t\t{\n\t\t\tint levels = 5;\n\t\t\tTreeNode root = new TreeNode(levels);\n\t\t\tint result = root.addTree(); // *\n\t\t\tvar slicingVariable1 = result; // *\n\t\t\tSystem.Console.WriteLine(\"Done!\");\n\t\t}\n\t}\n\n\tinternal class TreeNode\n\t{\n\t\tprivate int value = 0;\n\t\tprivate TreeNode left = null;\n\t\tprivate TreeNode right = null;\n\n\t\tinternal TreeNode(int levels)\n\t\t{\n\t\t\tvalue = 1;\n\t\t\tif (levels <= 1)\n\t\t\t{\n\t\t\t\tif (levels <= 0)\n\t\t\t\t\tthrow new System.Exception(\"Number of levels must be positive no.\");\n\t\t\t\tleft = null;\n\t\t\t\tright = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tleft = new TreeNode(levels - 1);\n\t\t\t\tright = new TreeNode(levels - 1);\n\t\t\t}\n\t\t}\n\n\t\tinternal virtual int addTree()\n\t\t{\n\t\t\tint total = value; // *\n\t\t\tif (left != null) // *\n\t\t\t\ttotal += left.addTree(); // *\n\t\t\tif (right != null) // *\n\t\t\t\ttotal += right.addTree(); // *\n\t\t\treturn total; // *\n\t\t}\n\t}\n}
\n

After running the query I collect every line in every path, and I get these lines: {11, 12, 42, 43, 44, 45, 46, 47} (marked with // *).
\nIn this case, I expected more lines.

\n

For example,
\nIf I run the same query, recursively (with an external program) adding previous lines as new targets
\n(performing one query for line 12, but also for line 42, 43, 44, 45, .. etc.) I get these lines:
\n{9, 10, 11, 12, 19, 20, 21, 23, 25, 26, 28, 30, 31, 35, 36, 40, 42, 43, 44, 45, 46, 47}.
\nThis is what I really want, a kind of closure of data dependencies over control dependencies.
\nI thought that I can reach that using isAdditionalTaintStep but I see that is not the same,

\n

Any suggestions?
\nI want to avoid performing several queries for getting the final \"static slice\".
\nThanks everybody in advance,
\nRegards.

","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hi @asoifer,

\n

I'm sorry to say that our data-flow analysis has a specific limitation that disallows defining sources/sinks of a data-flow configuration based on paths found with that configuration. For the security queries we are writing, that has not been a big problem so far. In some cases, we've had to have two layers of data-flow, which we have managed by just introducing a separate copy of the whole data-flow analysis, and then each part can sit in it's own \"layer\". In this way we can define sources/sinks in one layer based on the results form the other layer.

\n

For C# this would be DataFlow, DataFlow2, DataFlow3, DataFlow4, DataFlow5. And as an example of actually combining such two layers, I will highlight path injection query in Python.

\n

But I think this would at best be a band-aid for the specific problem you are trying to solve, where I would assume you want to reach a fixed point, and not just do a few iterations at most.

\n

Also sorry for the very late reply. This question somehow slipped off the radar 😐

","upvoteCount":2,"url":"https://github.com/github/codeql/discussions/6239#discussioncomment-1355934"}}}
Discussion options

You must be logged in to vote

Hi @asoifer,

I'm sorry to say that our data-flow analysis has a specific limitation that disallows defining sources/sinks of a data-flow configuration based on paths found with that configuration. For the security queries we are writing, that has not been a big problem so far. In some cases, we've had to have two layers of data-flow, which we have managed by just introducing a separate copy of the whole data-flow analysis, and then each part can sit in it's own "layer". In this way we can define sources/sinks in one layer based on the results form the other layer.

For C# this would be DataFlow, DataFlow2, DataFlow3, DataFlow4, DataFlow5. And as an example of actually combining such two la…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@asoifer
Comment options

@niravx23
Comment options

Answer selected by adityasharad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants