Skip to content

Commit 2840b56

Browse files
committed
Merge branch 'main' of git@github.com:apache/tomcat.git into main
2 parents 52dfcd3 + 9e035e8 commit 2840b56

9 files changed

Lines changed: 64 additions & 10 deletions

File tree

‎java/org/apache/catalina/Session.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public interface Session {
212212

213213
/**
214214
* Returns the maximum time interval, in seconds, between client requests before the servlet container will
215-
* invalidate the session. A negative time indicates that the session should never time out.
215+
* invalidate the session. A zero or negative time indicates that the session should never time out.
216216
*
217217
* @return the maximum inactive interval in seconds
218218
*/
@@ -221,7 +221,7 @@ public interface Session {
221221

222222
/**
223223
* Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate
224-
* the session. A negative time indicates that the session should never time out.
224+
* the session. A zero or negative time indicates that the session should never time out.
225225
*
226226
* @param interval The new maximum interval
227227
*/

‎java/org/apache/catalina/ha/session/DeltaManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ public ClusterMessage requestCompleted(String sessionId, boolean expires) {
10851085
// check to see if we need to send out an access message
10861086
if (!expires && (msg == null)) {
10871087
long replDelta = System.currentTimeMillis() - session.getLastTimeReplicated();
1088-
if (session.getMaxInactiveInterval() >= 0 && replDelta > (session.getMaxInactiveInterval() * 1000L)) {
1088+
if (session.getMaxInactiveInterval() > 0 && replDelta > (session.getMaxInactiveInterval() * 1000L)) {
10891089
if (enableStatistics) {
10901090
counterSend_EVT_SESSION_ACCESSED.incrementAndGet();
10911091
}

‎java/org/apache/catalina/ha/session/DeltaSession.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void setOwner(Object owner) {
275275
public boolean isAccessReplicate() {
276276
long replDelta = System.currentTimeMillis() - getLastTimeReplicated();
277277
int maxInactiveInterval = getMaxInactiveInterval();
278-
return maxInactiveInterval >= 0 && replDelta > (maxInactiveInterval * 1000L);
278+
return maxInactiveInterval > 0 && replDelta > (maxInactiveInterval * 1000L);
279279
}
280280

281281
@Override

‎java/org/apache/catalina/manager/ManagerServlet.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,10 +1292,10 @@ protected void sessions(PrintWriter writer, ContextName cn, int idle, StringMana
12921292
session.expire();
12931293
expired++;
12941294
}
1295-
// Negative interval: session never times out (a context
1295+
// Non-positive interval: session never times out (a context
12961296
// session timeout of zero is stored as -1 minutes which
12971297
// becomes -60 seconds on the session)
1298-
if (session.getMaxInactiveInterval() < 0) {
1298+
if (session.getMaxInactiveInterval() <= 0) {
12991299
notimeout++;
13001300
} else {
13011301
// Clamp negative idle time (system clock went backwards)

‎java/org/apache/catalina/manager/host/HostManagerServlet.java‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
2727
import java.nio.file.StandardCopyOption;
28+
import java.util.Locale;
2829
import java.util.StringTokenizer;
2930

3031
import javax.management.InstanceNotFoundException;
@@ -309,7 +310,13 @@ private static boolean pathCheck(File input, File expected, PrintWriter writer,
309310
}
310311

311312

312-
// -------------------------------------------------------- Private Methods
313+
private static String normalizeHostName(String hostName) {
314+
if (hostName == null) {
315+
return null;
316+
} else {
317+
return hostName.toLowerCase(Locale.ENGLISH);
318+
}
319+
}
313320

314321

315322
/**
@@ -340,6 +347,9 @@ protected synchronized void add(PrintWriter writer, String name, String aliases,
340347
return;
341348
}
342349

350+
// Normalize host name before it is used
351+
name = normalizeHostName(name);
352+
343353
// Check if host already exists
344354
if (engine.findChild(name) != null) {
345355
writer.println(smClient.getString("hostManagerServlet.alreadyHost", name));
@@ -456,6 +466,9 @@ protected synchronized void remove(PrintWriter writer, String name, StringManage
456466
return;
457467
}
458468

469+
// Normalize host name before it is used
470+
name = normalizeHostName(name);
471+
459472
// Check if host exists
460473
if (engine.findChild(name) == null) {
461474
writer.println(smClient.getString("hostManagerServlet.noHost", name));
@@ -534,6 +547,9 @@ protected void start(PrintWriter writer, String name, StringManager smClient) {
534547
return;
535548
}
536549

550+
// Normalize host name before it is used
551+
name = normalizeHostName(name);
552+
537553
Container host = engine.findChild(name);
538554

539555
// Check if host exists
@@ -585,6 +601,9 @@ protected void stop(PrintWriter writer, String name, StringManager smClient) {
585601
return;
586602
}
587603

604+
// Normalize host name before it is used
605+
name = normalizeHostName(name);
606+
588607
Container host = engine.findChild(name);
589608

590609
// Check if host exists
@@ -676,6 +695,9 @@ protected File getConfigBase(String hostName) {
676695
* @return the config base for the host
677696
*/
678697
protected File getConfigBase(String hostName, PrintWriter writer, StringManager smClient) {
698+
// Normalize host name before it is used
699+
hostName = normalizeHostName(hostName);
700+
679701
File configBase = new File(context.getCatalinaBase(), "conf");
680702
if (!configBase.exists()) {
681703
return null;

‎java/org/apache/catalina/session/StandardSession.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public StandardSession(Manager manager) {
166166

167167
/**
168168
* The maximum time interval, in seconds, between client requests before the servlet container may invalidate this
169-
* session. A negative time indicates that the session should never time out.
169+
* session. A zero or negative time indicates that the session should never time out.
170170
*/
171171
protected volatile int maxInactiveInterval = -1;
172172

‎test/org/apache/catalina/ha/session/TestDeltaSession.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,27 @@ public void valueBound(HttpSessionBindingEvent event) {
105105
Assert.assertNull(setAttributeException.get());
106106
Assert.assertNull(expireException.get());
107107
}
108+
109+
110+
@Test
111+
public void testIsAccessReplicateNonPositiveInterval() {
112+
DeltaSession session = new DeltaSession(new StandardManager());
113+
// Last replicated long enough ago to exceed any reasonable interval
114+
session.setLastTimeReplicated(System.currentTimeMillis() - 3600 * 1000L);
115+
116+
// Zero or negative means the session never times out so there is no
117+
// need to replicate access
118+
session.setMaxInactiveInterval(0);
119+
Assert.assertFalse(session.isAccessReplicate());
120+
session.setMaxInactiveInterval(-1);
121+
Assert.assertFalse(session.isAccessReplicate());
122+
123+
// Positive interval that has elapsed since last replication
124+
session.setMaxInactiveInterval(60);
125+
Assert.assertTrue(session.isAccessReplicate());
126+
127+
// Positive interval that has not yet elapsed
128+
session.setLastTimeReplicated(System.currentTimeMillis());
129+
Assert.assertFalse(session.isAccessReplicate());
130+
}
108131
}

‎test/org/apache/catalina/manager/TestManagerWebapp.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ public void testSessionsUnlimitedTimeout() throws Exception {
649649
unlimited.setMaxInactiveInterval(-1);
650650
manager.add(unlimited);
651651

652+
// An interval of zero also means the session never times out
653+
Session zeroInterval = manager.createSession(null);
654+
zeroInterval.setMaxInactiveInterval(0);
655+
manager.add(zeroInterval);
656+
652657
Session limited = manager.createSession(null);
653658
manager.add(limited);
654659

@@ -680,7 +685,7 @@ public boolean isResponseBodyOK() {
680685
client.processRequest(true);
681686
Assert.assertEquals(HttpServletResponse.SC_OK, client.getStatusCode());
682687
Assert.assertTrue(client.getResponseBody(),
683-
client.getResponseBody().contains("Unlimited time: [1] sessions"));
688+
client.getResponseBody().contains("Unlimited time: [2] sessions"));
684689
// The unlimited session must not also appear in an idle bucket
685690
Assert.assertTrue(client.getResponseBody(),
686691
client.getResponseBody().contains("Inactive for [<1] minutes: [1] sessions"));

‎webapps/docs/changelog.xml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<changelog>
113113
<scode>
114114
This release contains all of the changes up to and including those in
115-
Apache Tomcat 11.0.26 plus the additional changes listed below. (markt)
115+
Apache Tomcat 11.0.27 plus the additional changes listed below. (markt)
116116
</scode>
117117
<update>
118118
The minimum Java version has been updated to Java 21. (markt)
@@ -415,6 +415,10 @@
415415
Tapestry attributes, used for locale session sorting. (remm)
416416
</update>
417417
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
418+
<fix>
419+
Host Manager: Host names are now always converted to lower case before
420+
use. (markt)
421+
</fix>
418422
</changelog>
419423
</subsection>
420424
<subsection name="Tribes">

0 commit comments

Comments
 (0)