Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350189

Race condition in XMLSecurityManager

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 22
    • xml
    • None

      JDK-8306055 introduced `XMLSecurityManager#prepareCatalog`, which is called in the constructor, to initialize the built-in `JdkCatalog` via `JdkCatalog#init`.

      There is synchronization in `prepareCatalog`, but it seems to be problematic. First, the `lock` object is non-static. Since the method is called only once in the constructor, this look seems non-functional. Second, `jdkcatalogInitialized` is set to `true` before the catalog is actually initialized. Thus, a second thread calling `prepareCatalog` might see it as true although `JdkCatalog` is not initialized.

      I believe the following code would fix the issues:
      ```
          static volatile boolean jdkcatalogInitialized = false;
          private static final Object lock = new Object();

          private void prepareCatalog() {
              if (!jdkcatalogInitialized) {
                  synchronized (lock) {
                      if (!jdkcatalogInitialized) {
                          String resolve = getLimitValueAsString(Limit.JDKCATALOG_RESOLVE);
                          JdkCatalog.init(resolve);
                          jdkcatalogInitialized = true;
                      }
                  }
              }
          }
      ```

            joehw Joe Wang
            jeisl Josef Eisl
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: