[Soot-list] PatchingChain.insertBefore(Chain<E> toInsert, E point): bug?

Khilan Gudka khilan at doc.ic.ac.uk
Wed Dec 9 15:28:22 EST 2009


Hi,

The method PatchingChain.insertBefore(Chain<E> toInsert, E point) inserts
the chain "toInsert" just before "point" in the receiver chain. It does this
by calling PatchingChain.insertBefore(E toInsert, E point) for each Unit in
a reversed version of toInsert. To keep the correct control flow,
PatchingChain.insertBefore(E toInsert, E point) redirects jumps to "point"
to jump to "toInsert" instead. However, I've found that this leads to bugs
when inserting a chain that contains jumps itself. For example, inserting
the jimple code:

        if $r == 0 goto label0;
        staticinvoke <mypackage.MyClass: void m()>();
     label0:
        staticinvoke <mypackage.MyClass: void n()>();

Which corresponds to:

if($r) {
    MyClass.m();
}
MyClass.n();

Would be turned into the following when using the
above PatchingChain.insertBefore(Chain<E> toInsert, E point) method:

     label0:
        if $r == 0 goto label0;
        staticinvoke <mypackage.MyClass: void m()>();
        staticinvoke <mypackage.MyClass: void n()>();

The reason being that when insertBefore(E toInsert, E point) is repeatedly
called, the jump to "staticinvoke <mypackage.MyClass: void n()>();" is
redirected to the first statement "if $r == 0 goto label0;".

I think the solution is to, lastly, redirect jumps to "point" to the first
unit in toInsert (here is a snippet from the bottom
of PatchingChain.insertBefore(Chain<E> toInsert, E point) and the proposed
changes are in bold):

        E previousPoint = point;
        Iterator<E> it = backwardList.iterator();
        while (it.hasNext())
        {
            E o = it.next();
*            insertBeforeNoRedirect(o, previousPoint);*
            previousPoint = o;
        }

*        ((Unit) point).redirectJumpsToThisTo((Unit) toInsert.getFirst());*
*
*
Does this make sense or have I overlooked something?

Thanks,
Khilan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20091209/1ea6db83/attachment.html 


More information about the Soot-list mailing list