Ejemplo n.º 1
0
                public LinearEqualitiesForUnsafeCode Join(LinearEqualitiesForUnsafeCode prevState, Set <BoxedExpression> bottompointers, APC pc)
                {
                    LinearEqualitiesForUnsafeCode thiscloned = (LinearEqualitiesForUnsafeCode)this.Clone();
                    LinearEqualitiesForUnsafeCode prevcloned = (LinearEqualitiesForUnsafeCode)prevState.Clone();
                    IAbstractDomain joined = base.Join(prevState);
                    var             result = new LinearEqualitiesForUnsafeCode((LinearEqualitiesEnvironment <BoxedExpression>)joined, this.bdecoder, this.context, this.mdDecoder);

                    Set <BoxedExpression> thisvariables = thiscloned.Variables;
                    Set <BoxedExpression> prevvariables = prevcloned.Variables;

                    //For each pointer such that in a branch it is null and in the other is assigned to an allocated area of memory, we trace information only from
                    //this branch, ignoring the other one
                    foreach (BoxedExpression ptr in bottompointers)
                    {
                        BoxedExpression temp;
                        if (ptr.TryGetAssociatedInfo(pc, AssociatedInfo.WritableBytes, out temp) ||
                            ptr.TryGetAssociatedInfo(pc, AssociatedInfo.ArrayLength, out temp))
                        {
                            if (this.Variables.Contains(temp) && prevState.Variables.Contains(temp))
                            {
                                // Francesco: I added this check because it seems that something is wrong with the tracking for the null pointers
                                // (method System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(...) of System.Web.dll)
                                // The check should not influence the soundness (we are losing information)
                                continue;
                            }
                            else
                            {
                                RefineWithNullPointerInformation(pc, temp, thiscloned, prevcloned, ref result);
                            }
                        }
                    }
                    return(result);
                }
                protected override ReducedCartesianAbstractDomain <StripeWithIntervals <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> >, LinearEqualitiesEnvironment <BoxedExpression> > Factory(StripeWithIntervals <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> > left, LinearEqualitiesEnvironment <BoxedExpression> right)
                {
                    StripeWithIntervalsForUnsafeCode l;

                    if (left is StripeWithIntervalsForUnsafeCode)
                    {
                        l = (StripeWithIntervalsForUnsafeCode)left;
                    }
                    else
                    {
                        l = new StripeWithIntervalsForUnsafeCode((IntervalsForUnsafeCode)left.Left, (StripeForUnsafeCode)left.Right, this.decoder, this.context, this.mdDecoder);
                    }

                    LinearEqualitiesForUnsafeCode r;

                    if (right is LinearEqualitiesForUnsafeCode)
                    {
                        r = (LinearEqualitiesForUnsafeCode)right;
                    }
                    else
                    {
                        r = new LinearEqualitiesForUnsafeCode(right, this.decoder, this.context, this.mdDecoder);
                    }
                    StripeIntervalsKarrForUnsafeCode result = new StripeIntervalsKarrForUnsafeCode(l, r, decoder, encoder, context, this.mdDecoder);

                    foreach (BoxedExpression exp in this.nullPointers)
                    {
                        result.nullPointers.Add(exp);
                    }
                    return(result);
                }
 public StripeIntervalsKarrForUnsafeCode(
     StripeWithIntervalsForUnsafeCode /*!*/ left,
     LinearEqualitiesForUnsafeCode /*!*/ right,
     BoxedExpressionDecoder <Type, ExternalExpression> decoder,
     IExpressionEncoder <BoxedExpression> encoder,
     IExpressionContext <APC, Local, Parameter, Method, Field, Type, ExternalExpression, Variable> context,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> mdDecoder
     )
     : base(left, right, decoder, encoder)
 {
     this.decoder   = decoder;
     this.context   = context;
     this.mdDecoder = mdDecoder;
 }
Ejemplo n.º 4
0
                /// <summary>
                /// Given the length of a pointer that is null in one of the two branches of a join, add it to the domain all the contraints
                /// of the length that are on the other branch of the join
                /// </summary>
                /// <param name="pc">The pc at the join point</param>
                /// <param name="length">The length of the null pointer</param>
                /// <param name="result">The state on which we have to add the constraints</param>
                private void RefineWithNullPointerInformation(APC pc, BoxedExpression length, LinearEqualitiesForUnsafeCode thiscloned, LinearEqualitiesForUnsafeCode prevcloned, ref LinearEqualitiesForUnsafeCode result)
                {
                    Set <Polynomial <BoxedExpression> > eq = thiscloned.EqualsTo(length);

                    foreach (Polynomial <BoxedExpression> pol in eq)
                    {
                        IExpressionEncoder <BoxedExpression> encoder = BoxedExpressionEncoder.Encoder(this.mdDecoder, this.context);
                        BoxedExpression right = pol.ToPureExpression(encoder);
                        result = new LinearEqualitiesForUnsafeCode(result.TestTrueEqual(length, right), this.bdecoder, this.context, this.mdDecoder);
                    }
                    eq = prevcloned.EqualsTo(length);
                    foreach (Polynomial <BoxedExpression> pol in eq)
                    {
                        IExpressionEncoder <BoxedExpression> encoder = BoxedExpressionEncoder.Encoder(this.mdDecoder, this.context);
                        BoxedExpression right = pol.ToPureExpression(encoder);
                        result = new LinearEqualitiesForUnsafeCode(result.TestTrueEqual(length, right), this.bdecoder, this.context, this.mdDecoder);
                    }
                }
                /// <summary>
                /// It dispatches the join operator to the improved version in order to manage pointers that are null in one of the two branches
                /// </summary>
                public StripeIntervalsKarrForUnsafeCode Join(StripeIntervalsKarrForUnsafeCode prevState, APC pc)
                {
                    StripeWithIntervalsForUnsafeCode thisState_Left = this.Left as StripeWithIntervalsForUnsafeCode;
                    StripeWithIntervalsForUnsafeCode prevState_Left = prevState.Left as StripeWithIntervalsForUnsafeCode;

                    LinearEqualitiesForUnsafeCode thisState_Right = this.Right as LinearEqualitiesForUnsafeCode;
                    LinearEqualitiesForUnsafeCode prevState_Right = prevState.Right as LinearEqualitiesForUnsafeCode;

                    Debug.Assert(thisState_Left != null & thisState_Right != null & prevState_Left != null & prevState_Right != null);

                    // thisState_Right = PropagateConstants(thisState_Left.Left, thisState_Right);

                    StripeWithIntervalsForUnsafeCode joinLeftPart  = (StripeWithIntervalsForUnsafeCode)thisState_Left.Join(prevState_Left, pc);
                    LinearEqualitiesForUnsafeCode    joinRightPart = (LinearEqualitiesForUnsafeCode)thisState_Right.Join(prevState_Right, this.nullPointers.Union(prevState.nullPointers), pc);

                    nullPointers = new Set <BoxedExpression>();
                    return((StripeIntervalsKarrForUnsafeCode)prevState.Reduce(joinLeftPart, joinRightPart));
                }
                private LinearEqualitiesForUnsafeCode PropagateConstants(IntervalEnvironment <BoxedExpression> intervals, LinearEqualitiesForUnsafeCode equalities)
                {
                    foreach (var x in intervals.Variables)
                    {
                        Interval value = intervals[x];
                        if (!value.IsTop && !value.IsBottom && value.IsSingleton)
                        {
                            BoxedExpression valueAsExp = this.Encoder.ConstantFor((Int32)value.LowerBound);
                            BoxedExpression toAssume   = this.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.Equal, x, valueAsExp);

                            equalities = (LinearEqualitiesForUnsafeCode)equalities.TestTrue(toAssume);
                        }
                    }

                    return(equalities);
                }