sanitize systemd-notify message

Accept only READY= notify messages from the container.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2017-02-07 11:17:41 +01:00
parent 892f2ded6f
commit c8593c4d61
1 changed files with 20 additions and 1 deletions

View File

@ -3,6 +3,7 @@
package main
import (
"bytes"
"fmt"
"net"
"path/filepath"
@ -75,7 +76,25 @@ func (notifySocket *notifySocket) run() {
if err != nil {
break
}
var out bytes.Buffer
for _, line := range bytes.Split(buf[0:r], []byte{'\n'}) {
if bytes.HasPrefix(line, []byte("READY=")) {
_, err = out.Write(line)
if err != nil {
return
}
client.Write(buf[0:r])
_, err = out.Write([]byte{'\n'})
if err != nil {
return
}
_, err = client.Write(out.Bytes())
if err != nil {
return
}
return
}
}
}
}