Skip to content

Commit

Permalink
fix: fix validation issue in admin plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DrmagicE committed Dec 18, 2021
1 parent 675ff73 commit 14e39fa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions pkg/packets/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@ func readUint32(r *bytes.Buffer) (uint32, error) {
return binary.BigEndian.Uint32(r.Next(4)), nil
}

func readBinary(r *bytes.Buffer) (b []byte, err error) {
return readUTF8String(false, r)
}

func readUTF8String(mustUTF8 bool, r *bytes.Buffer) (b []byte, err error) {
if r.Len() < 2 {
return nil, codes.ErrMalformed
Expand Down Expand Up @@ -553,8 +549,6 @@ func ValidTopicFilter(mustUTF8 bool, p []byte) bool {
return true
}

// TopicMatch 返回topic和topic filter是否
//
// TopicMatch returns whether the topic and topic filter is matched.
func TopicMatch(topic []byte, topicFilter []byte) bool {
var spos int
Expand Down
2 changes: 1 addition & 1 deletion plugin/admin/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (p *publisher) mustEmbedUnimplementedPublishServiceServer() {

// Publish publishes a message into broker.
func (p *publisher) Publish(ctx context.Context, req *PublishRequest) (resp *empty.Empty, err error) {
if !packets.ValidV5Topic([]byte(req.TopicName)) {
if !packets.ValidTopicName(false, []byte(req.TopicName)) {
return nil, ErrInvalidArgument("topic_name", "")
}
if req.Qos > uint32(packets.Qos2) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/admin/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestPublisher_Publish_InvalidArgument(t *testing.T) {
name: "invalid_topic_name",
field: "topic_name",
req: &PublishRequest{
TopicName: "$share/a",
TopicName: "/a/b/+",
Qos: 2,
},
},
Expand Down

0 comments on commit 14e39fa

Please # to comment.