Skip to content

Commit 947dee7

Browse files
committedSep 12, 2023
8316113: Infinite permission checking loop in java/net/spi/InetAddressResolverProvider/RuntimePermissionTest
Reviewed-by: jpai, aefimov, dfuchs
1 parent 1d702d2 commit 947dee7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎test/jdk/java/net/spi/InetAddressResolverProvider/RuntimePermissionTest.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -63,7 +63,7 @@ private void testRuntimePermission(boolean permitInetAddressResolver) throws Exc
6363
ServiceConfigurationError sce =
6464
Assert.expectThrows(ServiceConfigurationError.class,
6565
() -> InetAddress.getByName("javaTest.org"));
66-
LOGGER.info("Got ServiceConfigurationError: " + sce);
66+
System.err.println("Got ServiceConfigurationError: " + sce);
6767
Throwable cause = sce.getCause();
6868
Assert.assertTrue(cause instanceof SecurityException);
6969
Assert.assertTrue(cause.getMessage().contains(RUNTIME_PERMISSION_NAME));
@@ -78,23 +78,25 @@ static class TestSecurityManager extends SecurityManager {
7878

7979
public TestSecurityManager(boolean permitInetAddressResolver) {
8080
this.permitInetAddressResolver = permitInetAddressResolver;
81-
LOGGER.info("inetAddressResolverProvider permission is " +
82-
(permitInetAddressResolver ? "granted" : "not granted"));
81+
System.err.println("inetAddressResolverProvider permission is " +
82+
(permitInetAddressResolver ? "granted" : "not granted"));
8383
}
8484

8585
@Override
8686
public void checkPermission(Permission permission) {
8787
if (permission instanceof RuntimePermission) {
88-
LOGGER.info("Checking RuntimePermission: " + permission);
8988
if (RUNTIME_PERMISSION_NAME.equals(permission.getName()) && !permitInetAddressResolver) {
90-
LOGGER.info("Denying '" + RUNTIME_PERMISSION_NAME + "' permission");
89+
System.err.println("Denying '" + RUNTIME_PERMISSION_NAME + "' permission");
9190
throw new SecurityException("Access Denied: " + RUNTIME_PERMISSION_NAME);
92-
}
91+
} else {
92+
// Do not do anything for non-matching Permission. Otherwise the test
93+
// has a chance to re-enter here recursively, e.g. due to permission
94+
// checks during class load. This would eventually overflow the stack.
95+
}
9396
}
9497
}
9598
}
9699

97100
private static final String RUNTIME_PERMISSION_NAME = "inetAddressResolverProvider";
98-
private static final Logger LOGGER = Logger.getLogger(RuntimePermissionTest.class.getName());
99101

100102
}

0 commit comments

Comments
 (0)
Please sign in to comment.