From 139215280f412b66d60ae83ff8ff6db8c0fd9cb0 Mon Sep 17 00:00:00 2001 From: Evgenij Ryazanov Date: Sat, 15 Jan 2022 11:14:30 +0800 Subject: [PATCH] Always specify charset for String.getBytes() in WebThread --- h2/src/main/org/h2/server/web/WebThread.java | 16 ++++++++++------ .../org/h2/store/fs/encrypt/FileEncrypt.java | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/h2/src/main/org/h2/server/web/WebThread.java b/h2/src/main/org/h2/server/web/WebThread.java index 471fda78d8..8180c15853 100644 --- a/h2/src/main/org/h2/server/web/WebThread.java +++ b/h2/src/main/org/h2/server/web/WebThread.java @@ -184,7 +184,7 @@ private boolean process() throws IOException { message += "Transfer-Encoding: chunked\r\n"; message += "\r\n"; trace(message); - output.write(message.getBytes()); + output.write(message.getBytes(StandardCharsets.ISO_8859_1)); while (it.hasNext()) { String s = it.next(); s = PageParser.parse(s, session.map); @@ -192,13 +192,14 @@ private boolean process() throws IOException { if (bytes.length == 0) { continue; } - output.write(Integer.toHexString(bytes.length).getBytes()); - output.write("\r\n".getBytes()); + output.write(Integer.toHexString(bytes.length).getBytes(StandardCharsets.ISO_8859_1)); + output.write(RN); output.write(bytes); - output.write("\r\n".getBytes()); + output.write(RN); output.flush(); } - output.write("0\r\n\r\n".getBytes()); + output.write('0'); + output.write(RNRN); output.flush(); return keepAlive; } @@ -217,7 +218,7 @@ private boolean process() throws IOException { message += "Content-Length: " + bytes.length + "\r\n"; message += "\r\n"; trace(message); - output.write(message.getBytes()); + output.write(message.getBytes(StandardCharsets.ISO_8859_1)); output.write(bytes); output.flush(); return keepAlive; @@ -252,6 +253,9 @@ private boolean checkHost(String host) throws IOException { if (index >= 0) { host = host.substring(0, index); } + if (host.isEmpty()) { + return false; + } if (host.equals(server.getHost()) || host.equals("localhost") || host.equals("127.0.0.1")) { return true; } diff --git a/h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java b/h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java index fea13dae0c..38bc227b04 100644 --- a/h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java +++ b/h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java @@ -10,6 +10,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.h2.security.AES; import org.h2.security.SHA256; @@ -37,7 +38,7 @@ public class FileEncrypt extends FileBaseDefault { */ static final int HEADER_LENGTH = BLOCK_SIZE; - private static final byte[] HEADER = "H2encrypt\n".getBytes(); + private static final byte[] HEADER = "H2encrypt\n".getBytes(StandardCharsets.ISO_8859_1); private static final int SALT_POS = HEADER.length; /**