negasus / haproxy-spoe-go

Haproxy SPOE (Stream Processing Offload Engine) Agent Golang implementation
MIT License
35 stars 12 forks source link

Problem acquiring messages with binary fields #1

Closed rikatz closed 4 years ago

rikatz commented 4 years ago

Hi,

Thanks for the work! Very useful :)

I'm trying to port the libmodsecurity SPOA to Golang using your library. It happens that when trying to acquire a message with a binary field (as req.hdr_bin) I get a panic, as following:

2019/11/13 21:22:57 listen 3000
panic: runtime error: index out of range [0] with length 0

goroutine 34 [running]:
github.com/negasus/haproxy-spoe-go/message.(*Messages).Decode(0xc00000e060, 0xc00001e0b2, 0x0, 0x1, 0x1, 0x53)
    /media/rkatz/data/rkatz/go/codes/haproxy-spoe-go/message/decode.go:22 +0x339
github.com/negasus/haproxy-spoe-go/frame.(*Frame).Read(0xc0000e8080, 0x562880, 0xc000072180, 0xc00010f000, 0xc00010c000)
    /media/rkatz/data/rkatz/go/codes/haproxy-spoe-go/frame/read.go:61 +0x3c4
github.com/negasus/haproxy-spoe-go/worker.(*worker).run(0xc0000e41e0, 0x0, 0x0)
    /media/rkatz/data/rkatz/go/codes/haproxy-spoe-go/worker/worker.go:53 +0x12c
github.com/negasus/haproxy-spoe-go/worker.Handle(0x5648e0, 0xc00010c000, 0x5461c0)
    /media/rkatz/data/rkatz/go/codes/haproxy-spoe-go/worker/worker.go:24 +0x66
created by github.com/negasus/haproxy-spoe-go/agent.(*Agent).Serve
    /media/rkatz/data/rkatz/go/codes/haproxy-spoe-go/agent/agent.go:31 +0xe7

I've been trying to dig into the code, but I'm not having success to dig what is going on. Is there any way to acquire binary fields?

This errors happens earlier, with no code, just with

mes, err := req.Messages.GetByName(messageName)
    if err != nil {
        log.Printf("message %s not found: %v", messageName, err)
        return
    }

Is there anything I'm missing?

Thank you!!

rikatz commented 4 years ago

@negasus just marking you here to be sure at least You get notified by this issue :)

negasus commented 4 years ago

@rikatz thank you for first issue) I will check bug

negasus commented 4 years ago

@rikatz solved. Pushed version v1.0.0

rikatz commented 4 years ago

I'll test right now!! Thank you very much!

negasus commented 4 years ago

Waiting for feedback)

rikatz commented 4 years ago

@negasus It works as expected:

2019/11/14 13:31:45 METHOD: POST
2019/11/14 13:31:45 path: /
2019/11/14 13:31:45 query: %!s(<nil>)
2019/11/14 13:31:45 reqver: 1.1
2019/11/14 13:31:45 reqhdrs: [4 104 111 115 116 14 49 55 50 46 49 54 46 50 50 52 46 49 51 55 10 117 115 101 114 45 97 103 101 110 116 11 99 117 114 108 47 55 46 53 56 46 48 6 97 99 99 101 112 116 3 42 47 42 14 99 111 110 116 101 110 116 45 108 101 110 103 116 104 2 49 48 12 99 111 110 116 101 110 116 45 116 121 112 101 33 97 112 112 108 105 99 97 116 105 111 110 47 120 45 119 119 119 45 102 111 114 109 45 117 114 108 101 110 99 111 100 101 100 0 0]

Will now build a function here to decode the headers into a map :)

Thank you very much!