Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when using java.lang.System.out/java.lang.System.err #75

Open
katyacyfra opened this issue Oct 17, 2023 · 0 comments
Open

NPE when using java.lang.System.out/java.lang.System.err #75

katyacyfra opened this issue Oct 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@katyacyfra
Copy link
Collaborator

I run USVM on the the following function (Java Juliet test suite)

    public void bad() throws Throwable
    {
        byte data;

        /* POTENTIAL FLAW: Use the maximum size of the data type */
        data = Byte.MAX_VALUE;

        /* POTENTIAL FLAW: if data == Byte.MAX_VALUE, this will overflow */
        byte result = (byte)(data + 1);

        IO.writeLine("result: " + result);

    }

IO is implemented as follows.

There is an unexpected NPE during the USVM run.

Instruction: %0.println(arg$0)
Exception: JcException: Address: 0x15, type: java.lang.NullPointerException
Call stack (contains 2 frames):
	0: UCallStackFrame(method=(id:73)javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01#bad(), returnSite=null)
	1: UCallStackFrame(method=(id:73)javajuliet.testcasesupport.IO#writeLine(java.lang.String), returnSite=javajuliet.testcasesupport.IO.writeLine(%7))

Assignments to null:

Instruction: java.lang.System.out = null
Call stack (contains 3 frames):
	0: UCallStackFrame(method=(id:73)javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01#bad(), returnSite=null)
	1: UCallStackFrame(method=(id:73)javajuliet.testcasesupport.IO#writeLine(java.lang.String), returnSite=javajuliet.testcasesupport.IO.writeLine(%7))
	2: UCallStackFrame(method=(id:1)java.lang.System#<clinit>(), returnSite=%0 = java.lang.System.out)
================================================================
Instruction: java.lang.System.err = null
Call stack (contains 3 frames):
	0: UCallStackFrame(method=(id:73)javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01#bad(), returnSite=null)
	1: UCallStackFrame(method=(id:73)javajuliet.testcasesupport.IO#writeLine(java.lang.String), returnSite=javajuliet.testcasesupport.IO.writeLine(%7))
	2: UCallStackFrame(method=(id:1)java.lang.System#<clinit>(), returnSite=%0 = java.lang.System.out)

And the final result is

20:08:04.945 |I| TestRunnerKt - 1 executions were found:
	JcTest(method=org.jacodb.impl.types.JcTypedMethodImpl@7131da33, before=JcParametersState(thisInstance=javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01@6a278584, parameters=[]), after=JcParametersState(thisInstance=javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01@28f90752, parameters=[]), result=Failure(java.lang.NullPointerException), coverage=JcCoverage(targetClassToCoverage={}))
Extracted values:
	[javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_max_add_01@6a278584, null]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant