Skip to content

Commit

Permalink
8316113: Infinite permission checking loop in java/net/spi/InetAddres…
Browse files Browse the repository at this point in the history
…sResolverProvider/RuntimePermissionTest

Backport-of: 947dee7f2d5f7295ab7fc47c7823d0662d3c07ff
  • Loading branch information
shipilev committed Sep 14, 2023
1 parent 42e5cd8 commit 5524b5e
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -63,7 +63,7 @@ private void testRuntimePermission(boolean permitInetAddressResolver) throws Exc
ServiceConfigurationError sce =
Assert.expectThrows(ServiceConfigurationError.class,
() -> InetAddress.getByName("javaTest.org"));
LOGGER.info("Got ServiceConfigurationError: " + sce);
System.err.println("Got ServiceConfigurationError: " + sce);
Throwable cause = sce.getCause();
Assert.assertTrue(cause instanceof SecurityException);
Assert.assertTrue(cause.getMessage().contains(RUNTIME_PERMISSION_NAME));
Expand All @@ -78,23 +78,25 @@ static class TestSecurityManager extends SecurityManager {

public TestSecurityManager(boolean permitInetAddressResolver) {
this.permitInetAddressResolver = permitInetAddressResolver;
LOGGER.info("inetAddressResolverProvider permission is " +
(permitInetAddressResolver ? "granted" : "not granted"));
System.err.println("inetAddressResolverProvider permission is " +
(permitInetAddressResolver ? "granted" : "not granted"));
}

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

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

}

1 comment on commit 5524b5e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.