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

Sandboxed test is not compiling because of illegal unicode escape #1134

Closed
alisevych opened this issue Oct 11, 2022 · 1 comment · Fixed by #1182
Closed

Sandboxed test is not compiling because of illegal unicode escape #1134

alisevych opened this issue Oct 11, 2022 · 1 comment · Fixed by #1182
Assignees
Labels
ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Oct 11, 2022

Description

Sandboxed test is not compiling because commented stack trace contains "illegal unicode escape".

To Reproduce

  1. Run a project in IntelliJ Idea 2022.1.3 - 2022.2.2
  2. Install RC plugin build
  3. Set Fuzzing to 100% (in File -> Settings -> Tools -> UnitTestBot)
  4. Add the following class (originally posted in Add SecurityManager support to block suspicious code #622 #625 ):
public class SecurityCheck {

    public int normalTest(int value) {
        if (value < 0) {
            return -value;
        }
        return value;
    }

    public int read(File path) throws IOException {
        byte[] bytes = Files.readAllBytes(path.toPath());
        return bytes.length;
    }

    public int connect(Socket socket) throws IOException {
        socket.connect(new InetSocketAddress("0.0.0.0", 22));
        return 0;
    }

    public String property(String key) {
        return System.getProperty(key);
    }

    public String systemExit() {
        System.exit(0);
        return "bad";
    }

}
  1. Generate tests with UnitTestBot
  2. Open generated tests

Expected behavior

Project can be successfully build after test generation.

Actual behavior

SecurityCheckTest is not compiled.
The following error is displayed:

C:\Users\<user_name>\UTBotJava\utbot-sample\src\test\java\org\utbot\examples\securitycheck\SecurityCheckTest.java:2823: error: illegal unicode escape
        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: access denied ("java.io.FilePermission" "jkmqh\uhauh" "read")]

Visual proofs (screenshots, logs, images)

image

There is the following test generated by Fuzzer

    ///region FUZZER: EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS for method read(java.io.File)

    @Test
    @DisplayName("read: path = File(String, String)")
    @Disabled(value = "Disabled due to sandbox")
    public void testRead() {
        SecurityCheck securityCheck = new SecurityCheck();
        File path = new File("jkmqh", "uhauh");
        
        /* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: access denied ("java.io.FilePermission" "jkmqh\uhauh" "read")]
            java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
            java.base/java.security.AccessController.checkPermission(AccessController.java:897)
            java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
            java.base/java.lang.SecurityManager.checkRead(SecurityManager.java:661)
            java.base/sun.nio.fs.WindowsChannelFactory.open(WindowsChannelFactory.java:299)
            java.base/sun.nio.fs.WindowsChannelFactory.newFileChannel(WindowsChannelFactory.java:168)
            java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
            java.base/java.nio.file.Files.newByteChannel(Files.java:371)
            java.base/java.nio.file.Files.newByteChannel(Files.java:422)
            java.base/java.nio.file.Files.readAllBytes(Files.java:3206)
            org.utbot.examples.securitycheck.SecurityCheck.read(SecurityCheck.java:19) */
    }
    ///endregion

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.2

Additional context

Originally posted by @alisevych in #1125 (comment)

@korifey korifey moved this to Todo in UTBot Java Oct 11, 2022
@alisevych alisevych added the ctg-bug Issue is a bug label Oct 11, 2022
@alisevych alisevych added this to the 2022.11 Release milestone Oct 11, 2022
@Markoutte
Copy link
Collaborator

Looks like that it is relative to #609

Reproducable for a simple example without sandboxing (fuzzer is on, test should fail):

public int error() {
    Integer.parseInt("my" + "\\" + "union");
    return -1;
}

@Vassiliy-Kudryashov could you please take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants