mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Yannick Lecaillez
25.46.2016 7974e68ba5e3396ea369b3522ab24ce9350c4633
OPENDJ-3529: NPE when connection is closed during handleAccept()

Because downtream is not set when invoking the factory, a NPE can happen
if the factory try to close the provided LDAPClientContext.
1 files modified
18 ■■■■■ changed files
opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/LDAPServerFilter.java 18 ●●●●● patch | view | raw | blame | history
opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/LDAPServerFilter.java
@@ -315,16 +315,13 @@
        @Override
        public NextAction handleRead(final FilterChainContext ctx)  {
            final GrizzlyBackpressureSubscription immutableRef = downstream;
            if (immutableRef != null) {
                return immutableRef.handleRead(ctx);
            }
            ctx.suspend();
            return ctx.getSuspendAction();
            // handleRead() is invoked only after handleAccept() completion, downstream cannot be null.
            return downstream.handleRead(ctx);
        }
        @Override
        public void exceptionOccurred(final FilterChainContext ctx, final Throwable error) {
            // downstream can be null if an error happen before handleAccept() completion.
            final GrizzlyBackpressureSubscription immutableRef = downstream;
            if (immutableRef != null) {
                immutableRef.onError(error);
@@ -336,6 +333,7 @@
        @Override
        public NextAction handleClose(final FilterChainContext ctx) {
            isClosed = true;
            // downstream can be null if the connection is closed before handleAccept() completion.
            final GrizzlyBackpressureSubscription immutableRef = downstream;
            if (immutableRef != null) {
                immutableRef.onComplete();
@@ -501,11 +499,6 @@
            connection.closeSilently();
        }
        private void closeConnection() {
            downstream.cancel();
            connection.closeSilently();
        }
        @Override
        public void disconnect(final ResultCode resultCode, final String diagnosticMessage) {
            notifyConnectionDisconnected(resultCode, diagnosticMessage);
@@ -516,7 +509,8 @@
            ).doAfterTerminate(new Action() {
                @Override
                public void run() throws Exception {
                    closeConnection();
                    // handleClose() will be invoked once this connection has been closed.
                    connection.closeSilently();
                }
            }).subscribe();
        }