Example #1
0
        public override void VisitIncludingEx(IncludingEx x)
        {
            switch (x.InclusionType)
            {
            case InclusionTypes.Include:
                ConsumeToken(Tokens.T_INCLUDE, "include", x.Span.Start);
                break;

            case InclusionTypes.IncludeOnce:
                ConsumeToken(Tokens.T_INCLUDE_ONCE, "include_once", x.Span.Start);
                break;

            case InclusionTypes.Require:
                ConsumeToken(Tokens.T_REQUIRE, "require", x.Span.Start);
                break;

            case InclusionTypes.RequireOnce:
                ConsumeToken(Tokens.T_REQUIRE_ONCE, "require_once", x.Span.Start);
                break;

            default:
                throw new ArgumentException();    // ??
            }

            VisitElement(x.Target);
        }
Example #2
0
 override public void VisitIncludingEx(IncludingEx x)
 {
     _serializer.StartSerialize(typeof(IncludingEx).Name, SerializeSpan(x.Span),
                                new NodeObj("InclusionType", x.InclusionType.ToString()),
                                new NodeObj("IsConditional", x.IsConditional.ToString()));
     base.VisitIncludingEx(x);
     _serializer.EndSerialize();
 }
            public override void VisitIncludingEx(IncludingEx x)
            {
                VisitSpecificElementProlog();

                SerializeToken(nameof(x.InclusionType), x.InclusionType.ToString(), null);
                SerializeToken(nameof(x.IsConditional), x.IsConditional.ToString(), null);

                base.VisitIncludingEx(x);
            }
Example #4
0
 /// <summary>
 /// Visit include target.
 /// </summary>
 /// <param name="x"></param>
 virtual public void VisitIncludingEx(IncludingEx x)
 {
     VisitElement(x.Target);
 }
Example #5
0
        public override void VisitIncludingEx(IncludingEx x)
        {
            var possibleFiles = CreateRValue(x.Target);

            Result(new IncludingExPoint(x, possibleFiles));
        }
Example #6
0
 void IReductionsSink.InclusionReduced(Parser /*!*/ parser, IncludingEx /*!*/ incl)
 {
     this.inclusionCount++;
 }
Example #7
0
 void IReductionsSink.InclusionReduced(Parser /*!*/ parser, IncludingEx /*!*/ incl)
 {
 }
Example #8
0
 /// <inheritdoc />
 public override void VisitIncludingEx(IncludingEx x)
 {
     RValueResult(x);
 }
Example #9
0
        public override void VisitIncludingEx(IncludingEx x)
        {
            Console.WriteLine("INCEX");

            base.VisitIncludingEx(x);
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IncludingExPoint" /> class.
 /// </summary>
 /// <param name="include">Inclusion expression</param>
 /// <param name="includePath">Program point with path of remote file</param>
 internal IncludingExPoint(IncludingEx include, ValuePoint includePath)
     : base(null, null, new ValuePoint[] { includePath })
 {
     Include     = include;
     IncludePath = includePath;
 }
Example #11
0
 private static RequireFileExpression ToRequireFileExpression(IncludingEx e)
 {
     return(new RequireFileExpression((RequireFileExpression.InclusionType)e.InclusionType, Parse(e.Target)));
 }
Example #12
0
        /// <summary>
        /// Is called after each include/require/include_once/require_once expression (can be resolved according to flow.CurrentPartial)
        /// </summary>
        /// <param name="flow">Flow controller where include extensions can be stored</param>
        /// <param name="includeFile">File argument of include statement</param>
        public override void Include(FlowController flow, MemoryEntry includeFile)
        {
            if (FlagsHandler.IsDirty(includeFile.PossibleValues, FlagType.FilePathDirty))
            {
                AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisSecurityWarning(flow.CurrentScript.FullName, flow.CurrentPartial, flow.CurrentProgramPoint, FlagType.FilePathDirty, ""));
            }

            bool isAlwaysConcrete = true;
            //extend current program point as Include
            List <string> files = FunctionResolver.GetFunctionNames(includeFile, flow, out isAlwaysConcrete);

            if (isAlwaysConcrete == false)
            {
                AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "Couldn't resolve all possible includes", flow.CurrentPartial, flow.CurrentProgramPoint, AnalysisWarningCause.COULDNT_RESOLVE_ALL_INCLUDES));
            }


            IncludingEx includeExpression = flow.CurrentPartial as IncludingEx;

            foreach (var branchKey in flow.ExtensionKeys)
            {
                if (!files.Remove(branchKey as string))
                {
                    //this include is now not resolved as possible include branch
                    flow.RemoveExtension(branchKey);
                }
            }

            int numberOfWarnings = 0;
            var includedFiles    = flow.OutSet.GetControlVariable(new VariableName(".includedFiles")).ReadMemory(flow.OutSet.Snapshot);

            foreach (var file in files)
            {
                var fileInfo = findFile(flow, file);

                if (fileInfo == null)
                {
                    AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "The file " + file + " to be included not found", flow.CurrentProgramPoint.Partial, flow.CurrentProgramPoint, AnalysisWarningCause.FILE_TO_BE_INCLUDED_NOT_FOUND));
                    numberOfWarnings++;
                    continue;
                }

                string fileName = fileInfo.FullName;

                // Handling include_once, require_once
                var varIncluded = flow.OutSet.GetControlVariable(new VariableName(fileName));
                if (includeExpression.InclusionType == InclusionTypes.IncludeOnce || includeExpression.InclusionType == InclusionTypes.RequireOnce)
                {
                    var includedInfo = varIncluded.ReadMemory(flow.OutSet.Snapshot);
                    if (includedInfo != null)
                    {
                        var includeType = (includeExpression.InclusionType == InclusionTypes.IncludeOnce) ? "include_once" : "require_once";
                        if (includedInfo.PossibleValues.Count() > 1)
                        {
                            //TODO: report or not?
                            //AnalysisWarningHandler.SetWarning (flow.OutSet, new AnalysisWarning (flow.CurrentScript.FullName, includeType + " is called more times in some program paths with the file " + fileName, flow.CurrentProgramPoint.Partial, flow.CurrentProgramPoint, AnalysisWarningCause.INCLUDE_REQUIRE_ONCE_CALLED_MORE_TIMES_WITH_SAME_FILE));
                            // TODO: include the file or not??
                            continue;
                        }
                        else
                        {
                            if (!(includedInfo.PossibleValues.First() is UndefinedValue))
                            {
                                //TODO: report or not?
                                //AnalysisWarningHandler.SetWarning (flow.OutSet, new AnalysisWarning (flow.CurrentScript.FullName, includeType + " is called more times with the file " + fileName, flow.CurrentProgramPoint.Partial, flow.CurrentProgramPoint, AnalysisWarningCause.INCLUDE_REQUIRE_ONCE_CALLED_MORE_TIMES_WITH_SAME_FILE));
                                continue;
                            }
                        }
                    }
                }


                // Avoid recursive includes
                // the file was never included
                int numberOfIncludes = -1;
                // TODO: optimization - avoid iterating all included files
                //  - make .includedFiles associative array with names of functions as indexes
                foreach (InfoValue <NumberOfCalls <string> > includeInfo in includedFiles.PossibleValues.Where(a => (a is InfoValue <NumberOfCalls <string> >)))
                {
                    if (includeInfo.Data.Callee == fileName)
                    {
                        numberOfIncludes = Math.Max(numberOfIncludes, includeInfo.Data.TimesCalled);
                    }
                }
                if (numberOfIncludes >= 0)
                {
                    if (numberOfIncludes > 2 || sharedFiles.Contains(fileName))
                    {
                        if (sharedFiles.Contains(fileName))
                        {
                            //set graph sharing for this function
                            if (!sharedProgramPoints.ContainsKey(fileName))
                            {
                                try
                                {
                                    //create single graph instance
                                    sharedProgramPoints[fileName] = ProgramPointGraph.FromSource(ControlFlowGraph.ControlFlowGraph.FromFile(fileInfo));
                                }
                                catch (ControlFlowGraph.ControlFlowException)
                                {
                                    numberOfWarnings++;
                                    AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "Control flow graph creation error", flow.CurrentPartial, flow.CurrentProgramPoint, AnalysisWarningCause.CFG_EXCEPTION_IN_INCLUDE_OR_EVAL));
                                }
                                catch (Parsers.ParserException)
                                {
                                    numberOfWarnings++;
                                    AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "Parser error", flow.CurrentPartial, flow.CurrentProgramPoint, AnalysisWarningCause.PARSER_EXCEPTION_IN_INCLUDE_OR_EVAL));
                                }
                            }

                            //get shared instance of program point graph
                            flow.AddExtension(fileName, sharedProgramPoints[fileName], ExtensionType.ParallelInclude);
                            continue;
                        }
                        else
                        {
                            sharedFiles.Add(fileName);
                        }
                    }
                }

                try
                {
                    // Write information about inclusion of the file
                    varIncluded.WriteMemory(flow.OutSet.Snapshot, new MemoryEntry(flow.OutSet.Snapshot.CreateBool(true)));

                    //Create graph for every include - NOTE: we can share pp graphs
                    var cfg     = ControlFlowGraph.ControlFlowGraph.FromFile(fileInfo);
                    var ppGraph = ProgramPointGraph.FromSource(cfg);
                    flow.AddExtension(fileName, ppGraph, ExtensionType.ParallelInclude);
                }
                catch (ControlFlowGraph.ControlFlowException)
                {
                    numberOfWarnings++;
                    AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "Control flow graph creation error", flow.CurrentPartial, flow.CurrentProgramPoint, AnalysisWarningCause.CFG_EXCEPTION_IN_INCLUDE_OR_EVAL));
                }
                catch (Parsers.ParserException)
                {
                    numberOfWarnings++;
                    AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisWarning(flow.CurrentScript.FullName, "Parser error", flow.CurrentPartial, flow.CurrentProgramPoint, AnalysisWarningCause.PARSER_EXCEPTION_IN_INCLUDE_OR_EVAL));
                }
            }

            if (numberOfWarnings > 0 && (includeExpression.InclusionType == InclusionTypes.Require || includeExpression.InclusionType == InclusionTypes.RequireOnce))
            {
                if (numberOfWarnings == files.Count && isAlwaysConcrete == true)
                {
                    fatalError(flow, true);
                }
                else
                {
                    fatalError(flow, false);
                }
            }
        }
Example #13
0
 /// <inheritdoc />
 override public void VisitIncludingEx(IncludingEx x)
 {
     VisitElement(x.Target);
     result = new IncludingEx(x.SourceUnit, x.Scope, x.IsConditional, x.Position, x.InclusionType, (Expression)result);
 }
Example #14
0
 /// <summary>
 /// Inspects a inclusion statement even during parsing
 /// </summary>
 /// <param name="parser">Parser currently analyzing the source code</param>
 /// <param name="decl">Current inclusion</param>
 public void InclusionReduced(Parser /*!*/ parser, IncludingEx /*!*/ decl)
 {
     compilationUnit.InclusionReduced(parser, decl);
 }