diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 3142389e..8e2177db 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -490,10 +490,14 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_connect) - + if enc == nil { + return errEncoding + } r.m_numInvokes += 1 enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) - + if enc == nil { + return errEncoding + } enc[0] = AMF_OBJECT enc = enc[1:] @@ -610,8 +614,14 @@ func C_RTMP_SendCreateStream(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_createStream) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] @@ -637,15 +647,20 @@ func C_SendReleaseStream(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_releaseStream) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] enc = C_AMF_EncodeString(enc, r.Link.playpath) if enc == nil { return errEncoding } - packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 0) @@ -668,8 +683,14 @@ func C_SendFCPublish(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_FCPublish) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] enc = C_AMF_EncodeString(enc, r.Link.playpath) @@ -699,12 +720,17 @@ func C_SendFCUnpublish(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_FCUnpublish) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] enc = C_AMF_EncodeString(enc, r.Link.playpath) - if enc == nil { return errEncoding } @@ -731,8 +757,14 @@ func C_SendPublish(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av_publish) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] enc = C_AMF_EncodeString(enc, r.Link.playpath) @@ -804,8 +836,10 @@ func C_SendBytesReceived(r *C_RTMP) error { enc := packet.m_body r.m_nBytesInSent = r.m_nBytesIn - C_AMF_EncodeInt32(enc, r.m_nBytesIn) - + enc = C_AMF_EncodeInt32(enc, r.m_nBytesIn) + if enc == nil { + return errEncoding + } packet.m_nBodySize = 4 return C_RTMP_SendPacket(r, &packet, 0) @@ -828,8 +862,14 @@ func C_SendCheckBW(r *C_RTMP) error { enc := packet.m_body enc = C_AMF_EncodeString(enc, av__checkbw) + if enc == nil { + return errEncoding + } r.m_numInvokes++ enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + if enc == nil { + return errEncoding + } enc[0] = AMF_NULL enc = enc[1:] @@ -1588,6 +1628,9 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) error { enc = pkt.m_body[:pkt.m_nBodySize] if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { enc = C_AMF_EncodeString(enc, setDataFrame) + if enc == nil { + return errEncoding + } pkt.m_nBytesRead = uint32(len(pkt.m_body) - len(enc)) }