|
|
68bf46 |
From 70345b5e5a6ad37399911194f0b746094061b399 Mon Sep 17 00:00:00 2001
|
|
|
68bf46 |
From: Mikolaj Izdebski <mizdebsk@redhat.com>
|
|
|
68bf46 |
Date: Wed, 2 Feb 2022 20:07:09 +0100
|
|
|
68bf46 |
Subject: [PATCH] Fix CVE-2022-23302 JMSSink
|
|
|
68bf46 |
|
|
|
68bf46 |
---
|
|
|
68bf46 |
.../java/org/apache/log4j/net/JMSSink.java | 153 ------------------
|
|
|
68bf46 |
1 file changed, 153 deletions(-)
|
|
|
68bf46 |
delete mode 100644 src/main/java/org/apache/log4j/net/JMSSink.java
|
|
|
68bf46 |
|
|
|
68bf46 |
diff --git a/src/main/java/org/apache/log4j/net/JMSSink.java b/src/main/java/org/apache/log4j/net/JMSSink.java
|
|
|
68bf46 |
deleted file mode 100644
|
|
|
68bf46 |
index 6a02831e..00000000
|
|
|
68bf46 |
--- a/src/main/java/org/apache/log4j/net/JMSSink.java
|
|
|
68bf46 |
+++ /dev/null
|
|
|
68bf46 |
@@ -1,153 +0,0 @@
|
|
|
68bf46 |
-/*
|
|
|
68bf46 |
- * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
68bf46 |
- * contributor license agreements. See the NOTICE file distributed with
|
|
|
68bf46 |
- * this work for additional information regarding copyright ownership.
|
|
|
68bf46 |
- * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
68bf46 |
- * (the "License"); you may not use this file except in compliance with
|
|
|
68bf46 |
- * the License. You may obtain a copy of the License at
|
|
|
68bf46 |
- *
|
|
|
68bf46 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
68bf46 |
- *
|
|
|
68bf46 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
68bf46 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
68bf46 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
68bf46 |
- * See the License for the specific language governing permissions and
|
|
|
68bf46 |
- * limitations under the License.
|
|
|
68bf46 |
- */
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-package org.apache.log4j.net;
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-import org.apache.log4j.Logger;
|
|
|
68bf46 |
-import org.apache.log4j.PropertyConfigurator;
|
|
|
68bf46 |
-import org.apache.log4j.spi.LoggingEvent;
|
|
|
68bf46 |
-import org.apache.log4j.xml.DOMConfigurator;
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-import javax.jms.JMSException;
|
|
|
68bf46 |
-import javax.jms.ObjectMessage;
|
|
|
68bf46 |
-import javax.jms.Session;
|
|
|
68bf46 |
-import javax.jms.Topic;
|
|
|
68bf46 |
-import javax.jms.TopicConnection;
|
|
|
68bf46 |
-import javax.jms.TopicConnectionFactory;
|
|
|
68bf46 |
-import javax.jms.TopicSession;
|
|
|
68bf46 |
-import javax.jms.TopicSubscriber;
|
|
|
68bf46 |
-import javax.naming.Context;
|
|
|
68bf46 |
-import javax.naming.InitialContext;
|
|
|
68bf46 |
-import javax.naming.NameNotFoundException;
|
|
|
68bf46 |
-import javax.naming.NamingException;
|
|
|
68bf46 |
-import java.io.BufferedReader;
|
|
|
68bf46 |
-import java.io.InputStreamReader;
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-/**
|
|
|
68bf46 |
- * A simple application that consumes logging events sent by a {@link
|
|
|
68bf46 |
- * JMSAppender}.
|
|
|
68bf46 |
- *
|
|
|
68bf46 |
- *
|
|
|
68bf46 |
- * @author Ceki Gülcü
|
|
|
68bf46 |
- * */
|
|
|
68bf46 |
-public class JMSSink implements javax.jms.MessageListener {
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- static Logger logger = Logger.getLogger(JMSSink.class);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- static public void main(String[] args) throws Exception {
|
|
|
68bf46 |
- if(args.length != 5) {
|
|
|
68bf46 |
- usage("Wrong number of arguments.");
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- String tcfBindingName = args[0];
|
|
|
68bf46 |
- String topicBindingName = args[1];
|
|
|
68bf46 |
- String username = args[2];
|
|
|
68bf46 |
- String password = args[3];
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- String configFile = args[4];
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- if(configFile.endsWith(".xml")) {
|
|
|
68bf46 |
- DOMConfigurator.configure(configFile);
|
|
|
68bf46 |
- } else {
|
|
|
68bf46 |
- PropertyConfigurator.configure(configFile);
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- new JMSSink(tcfBindingName, topicBindingName, username, password);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
|
|
68bf46 |
- // Loop until the word "exit" is typed
|
|
|
68bf46 |
- System.out.println("Type \"exit\" to quit JMSSink.");
|
|
|
68bf46 |
- while(true){
|
|
|
68bf46 |
- String s = stdin.readLine( );
|
|
|
68bf46 |
- if (s.equalsIgnoreCase("exit")) {
|
|
|
68bf46 |
- System.out.println("Exiting. Kill the application if it does not exit "
|
|
|
68bf46 |
- + "due to daemon threads.");
|
|
|
68bf46 |
- return;
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- public JMSSink( String tcfBindingName, String topicBindingName, String username,
|
|
|
68bf46 |
- String password) {
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- try {
|
|
|
68bf46 |
- Context ctx = new InitialContext();
|
|
|
68bf46 |
- TopicConnectionFactory topicConnectionFactory;
|
|
|
68bf46 |
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx,
|
|
|
68bf46 |
- tcfBindingName);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- TopicConnection topicConnection =
|
|
|
68bf46 |
- topicConnectionFactory.createTopicConnection(username,
|
|
|
68bf46 |
- password);
|
|
|
68bf46 |
- topicConnection.start();
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- TopicSession topicSession = topicConnection.createTopicSession(false,
|
|
|
68bf46 |
- Session.AUTO_ACKNOWLEDGE);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- Topic topic = (Topic)ctx.lookup(topicBindingName);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- topicSubscriber.setMessageListener(this);
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- } catch(JMSException e) {
|
|
|
68bf46 |
- logger.error("Could not read JMS message.", e);
|
|
|
68bf46 |
- } catch(NamingException e) {
|
|
|
68bf46 |
- logger.error("Could not read JMS message.", e);
|
|
|
68bf46 |
- } catch(RuntimeException e) {
|
|
|
68bf46 |
- logger.error("Could not read JMS message.", e);
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- public void onMessage(javax.jms.Message message) {
|
|
|
68bf46 |
- LoggingEvent event;
|
|
|
68bf46 |
- Logger remoteLogger;
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- try {
|
|
|
68bf46 |
- if(message instanceof ObjectMessage) {
|
|
|
68bf46 |
- ObjectMessage objectMessage = (ObjectMessage) message;
|
|
|
68bf46 |
- event = (LoggingEvent) objectMessage.getObject();
|
|
|
68bf46 |
- remoteLogger = Logger.getLogger(event.getLoggerName());
|
|
|
68bf46 |
- remoteLogger.callAppenders(event);
|
|
|
68bf46 |
- } else {
|
|
|
68bf46 |
- logger.warn("Received message is of type "+message.getJMSType()
|
|
|
68bf46 |
- +", was expecting ObjectMessage.");
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- } catch(JMSException jmse) {
|
|
|
68bf46 |
- logger.error("Exception thrown while processing incoming message.",
|
|
|
68bf46 |
- jmse);
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- protected static Object lookup(Context ctx, String name) throws NamingException {
|
|
|
68bf46 |
- try {
|
|
|
68bf46 |
- return ctx.lookup(name);
|
|
|
68bf46 |
- } catch(NameNotFoundException e) {
|
|
|
68bf46 |
- logger.error("Could not find name ["+name+"].");
|
|
|
68bf46 |
- throw e;
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-
|
|
|
68bf46 |
- static void usage(String msg) {
|
|
|
68bf46 |
- System.err.println(msg);
|
|
|
68bf46 |
- System.err.println("Usage: java " + JMSSink.class.getName()
|
|
|
68bf46 |
- + " TopicConnectionFactoryBindingName TopicBindingName username password configFile");
|
|
|
68bf46 |
- System.exit(1);
|
|
|
68bf46 |
- }
|
|
|
68bf46 |
-}
|
|
|
68bf46 |
--
|
|
|
68bf46 |
2.33.1
|
|
|
68bf46 |
|