From aac0801cdb63b1b5e88abbd2df252af1966cc3bf Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 6 Sep 2018 12:26:35 +0930 Subject: [PATCH] rtmp: use bytes.Equal for signature matching --- rtmp/rtmp.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index d2ffe248..4db77ec0 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -46,6 +46,7 @@ typedef struct sockaddr sockaddr; import "C" import ( + "bytes" "errors" "fmt" "log" @@ -1586,7 +1587,6 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) { // int HandShake(RTMP* r, int FP9HandShake); // rtmp.c +3744 func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) { - var bMatch int var uptime, suptime uint32 var typ byte //clientbuf := make([]byte, RTMP_SIG_SIZE+1) @@ -1642,15 +1642,9 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) { return false } - // TODO: find golang memcmp - bMatch = 0 - if memcmp(unsafe.Pointer(&serversig[0]), unsafe.Pointer(clientsig), - RTMP_SIG_SIZE) == 0 { - bMatch = 1 - } - - if bMatch == 0 { - log.Println("Client signature does not match!") + if !bytes.Equal(serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1]) { + log.Printf("Client signature does not match: %q != %q", + serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1]) } return true }