]> Cypherpunks.ru repositories - nncp.git/commitdiff
For safety join mail recipients with zero byte
authorSergey Matveev <stargrave@stargrave.org>
Fri, 16 Feb 2018 08:43:45 +0000 (11:43 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 16 Feb 2018 08:43:45 +0000 (11:43 +0300)
src/cypherpunks.ru/nncp/toss.go

index eb44f26a9878e2d95a3d7ab0c87f3354c620ab2c..dcdee6cd04c75dc3b55316741d78a0ccbc0685cb 100644 (file)
@@ -20,6 +20,7 @@ package nncp
 
 import (
        "bufio"
+       "bytes"
        "compress/zlib"
        "fmt"
        "io"
@@ -93,10 +94,13 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool {
                ctx.LogD("rx", sds, "taken")
                switch pkt.Type {
                case PktTypeMail:
-                       recipients := string(pkt.Path[:int(pkt.PathLen)])
+                       recipients := make([]string, 0)
+                       for _, recipient := range bytes.Split(pkt.Path[:int(pkt.PathLen)], []byte{0}) {
+                               recipients = append(recipients, string(recipient))
+                       }
                        sds := SdsAdd(sds, SDS{
                                "type": "mail",
-                               "dst":  recipients,
+                               "dst":  strings.Join(recipients, " "),
                        })
                        decompressor, err := zlib.NewReader(pipeR)
                        if err != nil {
@@ -112,10 +116,7 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun, doSeen bool) bool {
                        if !dryRun {
                                cmd := exec.Command(
                                        sendmail[0],
-                                       append(
-                                               sendmail[1:len(sendmail)],
-                                               strings.Split(recipients, " ")...,
-                                       )...,
+                                       append(sendmail[1:len(sendmail)], recipients...)...,
                                )
                                cmd.Env = append(cmd.Env, "NNCP_SENDER="+sender.Id.String())
                                cmd.Env = append(cmd.Env, "NNCP_NICE="+strconv.Itoa(int(pkt.Nice)))