Skip to content

Commit

Permalink
Always specify charset for String.getBytes() in WebThread
Browse files Browse the repository at this point in the history
  • Loading branch information
katzyn committed Jan 15, 2022
1 parent 9c88724 commit 1392152
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions h2/src/main/org/h2/server/web/WebThread.java
Expand Up @@ -184,21 +184,22 @@ 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);
bytes = s.getBytes(StandardCharsets.UTF_8);
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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion h2/src/main/org/h2/store/fs/encrypt/FileEncrypt.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down

0 comments on commit 1392152

Please sign in to comment.