You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sc...@apache.org on 2023/10/19 01:37:53 UTC

[tomcat] branch 9.0.x updated (e96a0ddc98 -> 7bc57d0d66)

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

schultz pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from e96a0ddc98 Use the proper API name
     new 3fed5bba41 Fail faster if a file does not exist.
     new 7bc57d0d66 Add a "chomp" capability to optionally remove a trailing newline from a file-based value.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../digester/ServiceBindingPropertySource.java     | 39 +++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)


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


[tomcat] 02/02: Add a "chomp" capability to optionally remove a trailing newline from a file-based value.

Posted by sc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7bc57d0d66ee7972a2419ace8346de40cb1a2811
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed Oct 18 21:31:50 2023 -0400

    Add a "chomp" capability to optionally remove a trailing newline from a file-based value.
---
 .../digester/ServiceBindingPropertySource.java     | 34 +++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java b/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
index fd882fcf63..a96e5d8285 100644
--- a/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
+++ b/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
@@ -42,6 +42,7 @@ import org.apache.tomcat.util.security.PermissionCheck;
  *                                            /keyFile
  *                                            /file
  *                                            /chainFile
+ *                                            /keyPassword
  * </pre>
  * <pre>
  *   {@code
@@ -49,10 +50,19 @@ import org.apache.tomcat.util.security.PermissionCheck;
  *           <Certificate certificateKeyFile="${custom-certificate.keyFile}"
  *                        certificateFile="${custom-certificate.file}"
  *                        certificateChainFile="${custom-certificate.chainFile}"
+ *                        certificateKeyPassword="${chomp:custom-certificate.keyPassword}"
  *                        type="RSA" />
  *     </SSLHostConfig> }
  * </pre>
  *
+ * <p>
+ *   The optional <code>chomp:</code> prefix will cause the ServiceBindingPropertySource
+ *   to trim a single newline (<code>\r\n</code>, <code>\r</code>, or <code>\n</code>)
+ *   from the end of the file, if it exists. This is a convenience for hand-edited
+ *   files/values where removing a trailing newline is difficult, and trailing
+ *   whitespace changes the meaning of the value.
+ * </p>
+ *
  * How to configure:
  * <pre>
  * {@code
@@ -98,6 +108,12 @@ public class ServiceBindingPropertySource implements IntrospectionUtils.SecurePr
             return null;
         }
 
+        boolean chomp = false;
+        if (key.startsWith("chomp:")) {
+            chomp = true;
+            key = key.substring(6); // Remove the "chomp:" prefix
+        }
+
         // we expect the keys to be in the format $SERVICE_BINDING_ROOT/<binding-name>/<key>
         String[] parts = key.split("\\.");
         if (parts.length != 2) {
@@ -117,7 +133,23 @@ public class ServiceBindingPropertySource implements IntrospectionUtils.SecurePr
                     return null;
                 }
             }
-            return new String(Files.readAllBytes(path));
+
+            byte[] bytes = Files.readAllBytes(path);
+
+            int length = bytes.length;
+
+            if (chomp) {
+                if(length > 1 && bytes[length - 2] == '\r' && bytes[length - 2] == '\n') {
+                    length -= 2;
+                } else if (length > 0) {
+                    byte c = bytes[length - 1];
+                    if (c == '\r' || c == '\n') {
+                        length -= 1;
+                    }
+                }
+            }
+
+            return new String(bytes, 0, length);
         } catch (IOException e) {
             return null;
         }


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


[tomcat] 01/02: Fail faster if a file does not exist.

Posted by sc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3fed5bba4196f8ee5c26b3a1a8b930bd58b17aad
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed Oct 18 21:31:05 2023 -0400

    Fail faster if a file does not exist.
---
 .../apache/tomcat/util/digester/ServiceBindingPropertySource.java    | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java b/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
index c6b7b6ae12..fd882fcf63 100644
--- a/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
+++ b/java/org/apache/tomcat/util/digester/ServiceBindingPropertySource.java
@@ -105,6 +105,11 @@ public class ServiceBindingPropertySource implements IntrospectionUtils.SecurePr
         }
 
         Path path = Paths.get(serviceBindingRoot, parts[0], parts[1]);
+
+        if (!path.toFile().exists()) {
+            return null;
+        }
+
         try {
             if (classLoader instanceof PermissionCheck) {
                 Permission p = new FilePermission(path.toString(), "read");


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