#vulnerable code 
                                protected boolean handleShell(Buffer buffer) throws IOException {
        boolean wantReply = buffer.getBoolean();

        if (((ServerSession) session).getServerFactoryManager().getShellFactory() == null) {
            return false;
        }
        addEnvVariable("USER", ((ServerSession) session).getUsername());
        shell = ((ServerSession) session).getServerFactoryManager().getShellFactory().createShell();
        out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
        err = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_EXTENDED_DATA);
        // Wrap in logging filters
        out = new LoggingFilterOutputStream(out, "OUT:", log);
        err = new LoggingFilterOutputStream(err, "ERR:", log);
        if (getPtyModeValue(PtyMode.ONLCR) != 0) {
            out = new LfToCrLfFilterOutputStream(out);
            err = new LfToCrLfFilterOutputStream(err);
        }
        in = new ChannelPipedInputStream(localWindow);
        shellIn = new ChannelPipedOutputStream((ChannelPipedInputStream) in);
        shell.setInputStream(in);
        shell.setOutputStream(out);
        shell.setErrorStream(err);
        shell.setExitCallback(new ShellFactory.ExitCallback() {
            public void onExit(int exitValue) {
                try {
                    closeShell(exitValue);
                } catch (IOException e) {
                    log.info("Error closing shell", e);
                }
            }
        });

        if (wantReply) {
            buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_SUCCESS);
            buffer.putInt(recipient);
            session.writePacket(buffer);
        }

        shell.start(env);
        shellIn = new LoggingFilterOutputStream(shellIn, "IN: ", log);

        return true;
    } 
                            #location 39 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                protected boolean handleShell(Buffer buffer) throws IOException {
        boolean wantReply = buffer.getBoolean();

        if (((ServerSession) session).getServerFactoryManager().getShellFactory() == null) {
            return false;
        }
        addEnvVariable("USER", ((ServerSession) session).getUsername());
        shell = ((ServerSession) session).getServerFactoryManager().getShellFactory().createShell();
        out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
        err = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_EXTENDED_DATA);
        // Wrap in logging filters
        out = new LoggingFilterOutputStream(out, "OUT:", log);
        err = new LoggingFilterOutputStream(err, "ERR:", log);
        if (getPtyModeValue(PtyMode.ONLCR) != 0) {
            out = new LfToCrLfFilterOutputStream(out);
            err = new LfToCrLfFilterOutputStream(err);
        }
        in = new ChannelPipedInputStream(localWindow);
        shellIn = new ChannelPipedOutputStream((ChannelPipedInputStream) in);
        shell.setInputStream(in);
        shell.setOutputStream(out);
        shell.setErrorStream(err);
        shell.setExitCallback(new ShellFactory.ExitCallback() {
            public void onExit(int exitValue) {
                try {
                    closeShell(exitValue);
                } catch (IOException e) {
                    log.info("Error closing shell", e);
                }
            }
        });

        if (wantReply) {
            buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_SUCCESS);
            buffer.putInt(recipient);
            session.writePacket(buffer);
        }

        shell.start(getEnvironment());
        shellIn = new LoggingFilterOutputStream(shellIn, "IN: ", log);

        return true;
    }