/patches/openjdk/8011139-revise_checking_getenclosingclass.patch

https://bitbucket.org/Ringdingcoder/icedtea6 · Patch · 58 lines · 52 code · 6 blank · 0 comment · 0 complexity · 7f510765bc8a489ef904e66bf0686990 MD5 · raw file

  1. changeset: 4968:2d3faf217561
  2. user: jfranck
  3. date: Thu Apr 18 13:18:28 2013 +0200
  4. files: src/share/classes/java/lang/Class.java
  5. description:
  6. 8011139: (reflect) Revise checking in getEnclosingClass
  7. Reviewed-by: darcy, mchung, ahgross
  8. --- openjdk/jdk/src/share/classes/java/lang/Class.java
  9. +++ openjdk/jdk/src/share/classes/java/lang/Class.java
  10. @@ -1134,13 +1134,9 @@
  11. enclosingCandidate = enclosingClass;
  12. }
  13. - // be very careful not to change the stack depth of this
  14. - // checkMemberAccess call for security reasons
  15. - // see java.lang.SecurityManager.checkMemberAccess
  16. - if (enclosingCandidate != null) {
  17. - enclosingCandidate.checkMemberAccess(Member.DECLARED,
  18. - Reflection.getCallerClass(), true);
  19. - }
  20. + if (enclosingCandidate != null)
  21. + enclosingCandidate.checkPackageAccess(
  22. + ClassLoader.getClassLoader(Reflection.getCallerClass()), true);
  23. return enclosingCandidate;
  24. }
  25. @@ -2214,6 +2210,8 @@
  26. * Check if client is allowed to access members. If access is denied,
  27. * throw a SecurityException.
  28. *
  29. + * This method also enforces package access.
  30. + *
  31. * <p> Default policy: allow all clients access with normal Java access
  32. * control.
  33. */
  34. @@ -2234,7 +2232,19 @@
  35. // checkMemberAccess of subclasses of SecurityManager as specified.
  36. s.checkMemberAccess(this, which);
  37. }
  38. + this.checkPackageAccess(ccl, checkProxyInterfaces);
  39. + }
  40. + }
  41. + /*
  42. + * Checks if a client loaded in ClassLoader ccl is allowed to access this
  43. + * class under the current package access policy. If access is denied,
  44. + * throw a SecurityException.
  45. + */
  46. + private void checkPackageAccess(final ClassLoader ccl, boolean checkProxyInterfaces) {
  47. + final SecurityManager s = System.getSecurityManager();
  48. + if (s != null) {
  49. + final ClassLoader cl = getClassLoader0();
  50. if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
  51. String name = this.getName();
  52. int i = name.lastIndexOf('.');