fixed the blind conversion of a byte array to a string when the array may not contain a valid and complete utf8 sequence. it should have been treated as a binary blob. conversion is now using base64 encoding

This commit is contained in:
2025-12-17 17:06:52 +09:00
parent 08f2fa2e09
commit 2ea3f52fd1
4 changed files with 60 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ package hodu
import "bufio"
import "context"
import "crypto/tls"
import "encoding/base64"
import "encoding/json"
import "errors"
import "fmt"
@@ -704,7 +705,7 @@ func (pxy *server_pxy_ssh_ws) ServeWebsocket(ws *websocket.Conn) (int, error) {
n, err = out.Read(buf[:])
if n > 0 {
var err2 error
err2 = send_ws_data_for_xterm(ws, "iov", string(buf[:n]))
err2 = send_ws_data_for_xterm(ws, "iov", base64.StdEncoding.EncodeToString(buf[:n]))
if err2 != nil {
s.log.Write(pxy.Id, LOG_ERROR, "[%s] Failed to send to websocket - %s", req.RemoteAddr, err2.Error())
break
@@ -777,7 +778,14 @@ ws_recv_loop:
if sess != nil {
var i int
for i, _ = range ev.Data {
in.Write([]byte(ev.Data[i]))
//in.Write([]byte(ev.Data[i]))
var bytes []byte
bytes, err = base64.StdEncoding.DecodeString(ev.Data[i])
if err != nil {
s.log.Write(pxy.Id, LOG_WARN, "[%s] Invalid pxy iov data received - %s", req.RemoteAddr, ev.Data[i])
} else {
in.Write(bytes)
}
}
}