Search in sources :

Example 1 with TaintedWithObjTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.

the class TaintUtils method enumValueOf.

public static <T extends Enum<T>> T enumValueOf(Class<T> enumType, String name, ControlTaintTagStack ctrl) {
    T ret = Enum.valueOf(enumType, name);
    Taint tag = (Taint) ((TaintedWithObjTag) ((Object) name)).getPHOSPHOR_TAG();
    tag = Taint.combineTags(tag, ctrl);
    if (tag != null && !(tag.getLabel() == null && tag.hasNoDependencies())) {
        ret = shallowClone(ret);
        ((TaintedWithObjTag) ret).setPHOSPHOR_TAG(tag);
    }
    return ret;
}
Also used : TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag) Taint(edu.columbia.cs.psl.phosphor.runtime.Taint)

Example 2 with TaintedWithObjTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.

the class ReflectionMasker method fixAllArgs.

@SuppressWarnings("rawtypes")
public static Object[] fixAllArgs(Object[] in, Constructor c, boolean isObjTags) {
    // System.out.println("Making constructo rcall to " + c);
    if (c != null && in != null && c.getParameterTypes().length != in.length) {
        Object[] ret = new Object[c.getParameterTypes().length];
        int j = 0;
        for (int i = 0; i < in.length; i++) {
            if (c.getParameterTypes()[j].isPrimitive()) {
                if (in[i] instanceof TaintedWithIntTag)
                    ret[j] = ((TaintedWithIntTag) in[i]).getPHOSPHOR_TAG();
                else if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = 0;
                j++;
            } else if (c.getParameterTypes()[j] == Configuration.TAINT_TAG_OBJ_CLASS) {
                if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = null;
                j++;
            } else if (LazyArrayIntTags.class.isAssignableFrom(c.getParameterTypes()[j])) {
                LazyArrayIntTags arr = ((LazyArrayIntTags) in[i]);
                if (arr == null) {
                    ret[j] = null;
                    j++;
                    ret[j] = null;
                    j++;
                } else {
                    ret[j] = arr.taints;
                    j++;
                    ret[j] = arr.getVal();
                    j++;
                }
                continue;
            } else if (LazyArrayObjTags.class.isAssignableFrom(c.getParameterTypes()[j])) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                if (arr == null) {
                    ret[j] = null;
                    j++;
                    ret[j] = null;
                    j++;
                } else {
                    ret[j] = arr.taints;
                    j++;
                    ret[j] = arr.getVal();
                    j++;
                }
                continue;
            }
            ret[j] = in[i];
            j++;
        }
        return ret;
    } else if (in == null && c.getParameterTypes().length == 1) {
        Object[] ret = new Object[1];
        ret[0] = null;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 2) {
        Object[] ret = new Object[2];
        ret[0] = new ControlTaintTagStack();
        ret[1] = null;
        return ret;
    }
    return in;
}
Also used : ControlTaintTagStack(edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)

Example 3 with TaintedWithObjTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.

the class ReflectionMasker method fixAllArgs.

public static Object[] fixAllArgs(Object[] in, Constructor c, ControlTaintTagStack ctrl) {
    // System.out.println("Making constructo rcall to " + c);
    if (c != null && in != null && c.getParameterTypes().length != in.length) {
        Object[] ret = new Object[c.getParameterTypes().length];
        int j = 0;
        for (int i = 0; i < in.length; i++) {
            if (c.getParameterTypes()[j].isPrimitive()) {
                if (in[i] instanceof TaintedWithIntTag)
                    ret[j] = ((TaintedWithIntTag) in[i]).getPHOSPHOR_TAG();
                else if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = 0;
                j++;
            } else if (c.getParameterTypes()[j] == Configuration.TAINT_TAG_OBJ_CLASS) {
                if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = null;
                j++;
            } else if (c.getParameterTypes()[j].isArray() && (c.getParameterTypes()[j].getComponentType().isPrimitive() || Configuration.TAINT_TAG_OBJ_CLASS.isAssignableFrom(c.getParameterTypes()[j].getComponentType()))) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                ret[j] = arr.taints;
                j++;
                ret[j] = arr.getVal();
                j++;
                continue;
            }
            ret[j] = in[i];
            j++;
        }
        ret[ret.length - 2] = ctrl;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 1) {
        Object[] ret = new Object[1];
        ret[0] = null;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 2) {
        Object[] ret = new Object[2];
        ret[0] = ctrl;
        ret[1] = null;
        return ret;
    }
    return in;
}
Also used : LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)

Example 4 with TaintedWithObjTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.

the class Taint method combineTagsOnObject.

@SuppressWarnings("rawtypes")
public static void combineTagsOnObject(Object o, ControlTaintTagStack tags) {
    if (tags.isEmpty() || IGNORE_TAINTING)
        return;
    if (Configuration.derivedTaintListener != null)
        Configuration.derivedTaintListener.controlApplied(o, tags);
    if (o instanceof TaintedWithObjTag) {
        if (o instanceof String) {
            Taint onObj = (Taint) ((TaintedWithObjTag) o).getPHOSPHOR_TAG();
            ((String) o).PHOSPHOR_TAG = Taint.combineTags(onObj, tags);
        // for(int i = 0; i < ((String) o).length(); i++)
        // {
        // ((String)o).valuePHOSPHOR_TAG[i] = Taint.combineTags(((String)o).valuePHOSPHOR_TAG[i], tags);
        // }
        } else
            ((TaintedWithObjTag) o).setPHOSPHOR_TAG(Taint.combineTags((Taint) ((TaintedWithObjTag) o).getPHOSPHOR_TAG(), tags));
    }
}
Also used : TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag) EnqueuedTaint(edu.columbia.cs.psl.phosphor.struct.EnqueuedTaint)

Example 5 with TaintedWithObjTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.

the class StringConcatObjTagITCase method testNewStringConcat.

@Test
public void testNewStringConcat() throws Exception {
    String str1 = new String("abcdefg");
    ((TaintedWithObjTag) ((Object) str1)).setPHOSPHOR_TAG(new Taint("sensitive"));
    String str2 = "a" + str1;
    assertTrue(MultiTainter.getTaint(str2.charAt(0)) == null);
    assertTrue(MultiTainter.getTaint(str2.charAt(1)) != null);
}
Also used : TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag) Taint(edu.columbia.cs.psl.phosphor.runtime.Taint) Test(org.junit.Test)

Aggregations

TaintedWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)13 Taint (edu.columbia.cs.psl.phosphor.runtime.Taint)8 TaintedWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag)5 LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)4 Test (org.junit.Test)4 LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)2 MethodInvoke (edu.columbia.cs.psl.phosphor.struct.MethodInvoke)2 ControlTaintTagStack (edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack)1 EnqueuedTaint (edu.columbia.cs.psl.phosphor.struct.EnqueuedTaint)1 TaintedPrimitiveWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag)1 TaintedPrimitiveWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag)1 HashMap (java.util.HashMap)1