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:
@@ -1,5 +1,6 @@
|
||||
package hodu
|
||||
|
||||
import "encoding/base64"
|
||||
import "encoding/json"
|
||||
import "errors"
|
||||
import "io"
|
||||
@@ -94,7 +95,7 @@ func (pty *client_pty_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 {
|
||||
c.log.Write(pty.Id, LOG_ERROR, "[%s] Failed to send to websocket - %s", req.RemoteAddr, err2.Error())
|
||||
break
|
||||
@@ -187,7 +188,14 @@ ws_recv_loop:
|
||||
if tty != 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 {
|
||||
c.log.Write(pty.Id, LOG_WARN, "[%s] Invalid iov data received - %s", req.RemoteAddr, ev.Data[i])
|
||||
} else {
|
||||
in.Write(bytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user