This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 74edb3133edb52af9b3490192aab27ec1c96194e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 28 12:13:34 2018 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=53411
    
    Improve the handling of HTTP requests that do not explicitly specify a
    host name when no default host is configured. Also improve the tracking
    of changes to the default host as hosts are added and removed while
    Tomcat is running.
---
 java/org/apache/catalina/core/LocalStrings.properties  |  1 -
 .../apache/catalina/core/LocalStrings_es.properties    |  1 -
 .../apache/catalina/core/LocalStrings_fr.properties    |  1 -
 .../apache/catalina/core/LocalStrings_ja.properties    |  1 -
 java/org/apache/catalina/core/StandardEngine.java      |  3 +++
 java/org/apache/catalina/core/StandardEngineValve.java | 18 ++----------------
 java/org/apache/catalina/mapper/Mapper.java            |  6 ++++--
 java/org/apache/catalina/mapper/MapperListener.java    | 14 ++++++++++----
 webapps/docs/changelog.xml                             |  6 ++++++
 9 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/java/org/apache/catalina/core/LocalStrings.properties 
b/java/org/apache/catalina/core/LocalStrings.properties
index 8343a22..787d4ba 100644
--- a/java/org/apache/catalina/core/LocalStrings.properties
+++ b/java/org/apache/catalina/core/LocalStrings.properties
@@ -217,7 +217,6 @@ standardContext.workPath=Exception obtaining work path for 
context [{0}]
 standardContextValve.acknowledgeException=Failed to acknowledge request with a 
100 (Continue) response
 
 standardEngine.jvmRouteFail=Failed to set Engine's jvmRoute attribute from 
system property
-standardEngine.noHost=No Host matches server name [{0}]
 standardEngine.notHost=Child of an Engine must be a Host
 standardEngine.notParent=Engine cannot have a parent Container
 
diff --git a/java/org/apache/catalina/core/LocalStrings_es.properties 
b/java/org/apache/catalina/core/LocalStrings_es.properties
index 66a20d0..3b439e7 100644
--- a/java/org/apache/catalina/core/LocalStrings_es.properties
+++ b/java/org/apache/catalina/core/LocalStrings_es.properties
@@ -146,7 +146,6 @@ standardContext.workPath=Excepción obteniendo ruta de 
trabajo para el contexto
 standardContextValve.acknowledgeException=No pude reconocer el requerimiento 
con una respuesta 100 (Continuar)
 
 standardEngine.jvmRouteFail=No pude poner el atributo jvmRoute del Motor para 
la propiedad del sistema
-standardEngine.noHost=No hay Máquina que coincida con nombre de servidor [{0}]
 standardEngine.notHost=El Hijo de un Motor debe de ser un Máquina
 standardEngine.notParent=El Motor no puede tener un Contenedor padre
 
diff --git a/java/org/apache/catalina/core/LocalStrings_fr.properties 
b/java/org/apache/catalina/core/LocalStrings_fr.properties
index ab87356..0dd5d95 100644
--- a/java/org/apache/catalina/core/LocalStrings_fr.properties
+++ b/java/org/apache/catalina/core/LocalStrings_fr.properties
@@ -216,7 +216,6 @@ standardContext.workPath=Impossible d''obtenir le chemin de 
travail pour le cont
 standardContextValve.acknowledgeException=Impossible de confirmer la requête 
avec une réponse 100 (continuer)
 
 standardEngine.jvmRouteFail=Impossible de fixer la jvmRoute de l'Engine à 
partir d'une propriété système
-standardEngine.noHost=Aucune hôte (host) ne correspond au nom de serveur [{0}]
 standardEngine.notHost=Le fils d'un moteur (child of an Engine) doit être un 
hôte
 standardEngine.notParent=Un moteur (engine) ne peut avoir de conteneur parent 
(container)
 
diff --git a/java/org/apache/catalina/core/LocalStrings_ja.properties 
b/java/org/apache/catalina/core/LocalStrings_ja.properties
index 2630d7d..24b73df 100644
--- a/java/org/apache/catalina/core/LocalStrings_ja.properties
+++ b/java/org/apache/catalina/core/LocalStrings_ja.properties
@@ -216,7 +216,6 @@ standardContext.workPath=コンテキスト[{0}]のworkパスを取得中の例
 standardContextValve.acknowledgeException=100 (Continue) 
レスポンスでリクエストを確認できませんでした。
 
 standardEngine.jvmRouteFail=EngineのjvmRoute属性をシステムプロパティから設定できませんでした
-standardEngine.noHost=サーバ名 [{0}] に一致するホストが存在しません
 standardEngine.notHost=Engineの子供はHostでなければいけません
 standardEngine.notParent=エンジンは親のコンテナを持つことはできません
 
diff --git a/java/org/apache/catalina/core/StandardEngine.java 
b/java/org/apache/catalina/core/StandardEngine.java
index 2522de6..4e7881c 100644
--- a/java/org/apache/catalina/core/StandardEngine.java
+++ b/java/org/apache/catalina/core/StandardEngine.java
@@ -149,6 +149,9 @@ public class StandardEngine extends ContainerBase 
implements Engine {
         } else {
             this.defaultHost = host.toLowerCase(Locale.ENGLISH);
         }
+        if (getState().isAvailable()) {
+            service.getMapper().setDefaultHostName(host);
+        }
         support.firePropertyChange("defaultHost", oldDefaultHost,
                                    this.defaultHost);
 
diff --git a/java/org/apache/catalina/core/StandardEngineValve.java 
b/java/org/apache/catalina/core/StandardEngineValve.java
index 8ec5ef3..96ef64e 100644
--- a/java/org/apache/catalina/core/StandardEngineValve.java
+++ b/java/org/apache/catalina/core/StandardEngineValve.java
@@ -19,13 +19,11 @@ package org.apache.catalina.core;
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.Host;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.valves.ValveBase;
-import org.apache.tomcat.util.res.StringManager;
 
 /**
  * Valve that implements the default basic behavior for the
@@ -44,15 +42,6 @@ final class StandardEngineValve extends ValveBase {
     }
 
 
-    // ----------------------------------------------------- Instance Variables
-
-    /**
-     * The string manager for this package.
-     */
-    private static final StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
     // --------------------------------------------------------- Public Methods
 
     /**
@@ -73,10 +62,8 @@ final class StandardEngineValve extends ValveBase {
         // Select the Host to be used for this Request
         Host host = request.getHost();
         if (host == null) {
-            response.sendError
-                (HttpServletResponse.SC_BAD_REQUEST,
-                 sm.getString("standardEngine.noHost",
-                              request.getServerName()));
+            // HTTP 0.9 or HTTP 1.0 request without a host when no default host
+            // is defined. This is handled by the CoyoteAdapter.
             return;
         }
         if (request.isAsyncSupported()) {
@@ -85,6 +72,5 @@ final class StandardEngineValve extends ValveBase {
 
         // Ask this Host to process this request
         host.getPipeline().getFirst().invoke(request, response);
-
     }
 }
diff --git a/java/org/apache/catalina/mapper/Mapper.java 
b/java/org/apache/catalina/mapper/Mapper.java
index d8f45df..7395a35 100644
--- a/java/org/apache/catalina/mapper/Mapper.java
+++ b/java/org/apache/catalina/mapper/Mapper.java
@@ -691,12 +691,14 @@ public final class Mapper {
                     MappingData mappingData) throws IOException {
 
         if (host.isNull()) {
+            if (defaultHostName == null) {
+                return;
+            }
             host.getCharChunk().append(defaultHostName);
         }
         host.toChars();
         uri.toChars();
-        internalMap(host.getCharChunk(), uri.getCharChunk(), version,
-                mappingData);
+        internalMap(host.getCharChunk(), uri.getCharChunk(), version, 
mappingData);
     }
 
 
diff --git a/java/org/apache/catalina/mapper/MapperListener.java 
b/java/org/apache/catalina/mapper/MapperListener.java
index 508fd6d..b918e8d 100644
--- a/java/org/apache/catalina/mapper/MapperListener.java
+++ b/java/org/apache/catalina/mapper/MapperListener.java
@@ -266,7 +266,7 @@ public class MapperListener extends LifecycleMBeanBase
 
         boolean found = false;
 
-        if (defaultHost != null && defaultHost.length() >0) {
+        if (defaultHost != null && defaultHost.length() > 0) {
             Container[] containers = engine.findChildren();
 
             for (Container container : containers) {
@@ -286,11 +286,10 @@ public class MapperListener extends LifecycleMBeanBase
             }
         }
 
-        if(found) {
+        if (found) {
             mapper.setDefaultHostName(defaultHost);
         } else {
-            log.warn(sm.getString("mapperListener.unknownDefaultHost",
-                    defaultHost, service));
+            log.error(sm.getString("mapperListener.unknownDefaultHost", 
defaultHost, service));
         }
     }
 
@@ -308,6 +307,10 @@ public class MapperListener extends LifecycleMBeanBase
                 registerContext((Context) container);
             }
         }
+
+        // Default host may have changed
+        findDefaultHost();
+
         if(log.isDebugEnabled()) {
             log.debug(sm.getString("mapperListener.registerHost",
                     host.getName(), domain, service));
@@ -324,6 +327,9 @@ public class MapperListener extends LifecycleMBeanBase
 
         mapper.removeHost(hostname);
 
+        // Default host may have changed
+        findDefaultHost();
+
         if(log.isDebugEnabled()) {
             log.debug(sm.getString("mapperListener.unregisterHost", hostname,
                     domain, service));
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ceab57a..a585ea2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -48,6 +48,12 @@
   <subsection name="Catalina">
     <changelog>
       <fix>
+        <bug>53411</bug>: Improve the handling of HTTP requests that do not
+        explicitly specify a host name when no default host is configured. Also
+        improve the tracking of changes to the default host as hosts are added
+        and removed while Tomcat is running. (markt)
+      </fix>
+      <fix>
         <bug>64582</bug>: Pre-load the <code>CoyoteOutputStream</code> class to
         prevent a potential exception when running under a security manager.
         Patch provided by Johnathan Gilday. (markt)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to