From 8c09df03aa5eeb581befb7bb77a0af44b39dfd37 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 20 Jan 2019 12:13:49 +0100 Subject: [PATCH] ctlsock: fix buffer truncation of JSON unmarshal error In the error case, buf was not restored to the original capacity. Instead of truncating "buf" and restoring (or forgetting to restore) later, introduce the "data" slice. Fixes https://github.com/rfjakob/gocryptfs/issues/356 --- internal/ctlsock/ctlsock_serve.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/ctlsock/ctlsock_serve.go b/internal/ctlsock/ctlsock_serve.go index 4b02948..8b19e8a 100644 --- a/internal/ctlsock/ctlsock_serve.go +++ b/internal/ctlsock/ctlsock_serve.go @@ -96,9 +96,9 @@ func (ch *ctlSockHandler) handleConnection(conn *net.UnixConn) { conn.Close() return } - buf = buf[:n] + data := buf[:n] var in RequestStruct - err = json.Unmarshal(buf, &in) + err = json.Unmarshal(data, &in) if err != nil { tlog.Warn.Printf("ctlsock: JSON Unmarshal error: %#v", err) err = errors.New("JSON Unmarshal error: " + err.Error()) @@ -106,8 +106,6 @@ func (ch *ctlSockHandler) handleConnection(conn *net.UnixConn) { continue } ch.handleRequest(&in, conn) - // Restore original size. - buf = buf[:cap(buf)] } }