Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix validation issue in admin plugin #152

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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