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 off-by-one error in upserts #423

Merged
merged 2 commits into from
Jan 9, 2023
Merged

Fix off-by-one error in upserts #423

merged 2 commits into from
Jan 9, 2023

Conversation

jkralik
Copy link
Member

@jkralik jkralik commented Jan 4, 2023

There are two off-by-one errors in the upsert functions for message ID and message type.
UpsertMessageId should allow a value of 65535, while UpsertType should allow 255.

Without this fix, a device sending a confirmable message to the server will receive an ACK message back with an incorrect Message ID.

FYI: @mniestroj @vitprajzler

There are two off-by-one errors in the upsert functions for message ID and
message type. UpsertMessageId should allow a value of 65535, while
UpsertType should allow 255.

Without this fix, a device sending a confirmable message to the server will
receive an ACK message back with an incorrect Message ID.

Co-authored-by: Vit Prajzler <28387418+vitprajzler@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 4, 2023

Codecov Report

Merging #423 (cb435b9) into master (2e2c858) will increase coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
+ Coverage   71.34%   71.46%   +0.12%     
==========================================
  Files          68       68              
  Lines        5255     5275      +20     
==========================================
+ Hits         3749     3770      +21     
+ Misses       1122     1119       -3     
- Partials      384      386       +2     
Impacted Files Coverage Δ
message/getmid.go 83.33% <100.00%> (+3.33%) ⬆️
message/message.go 80.00% <100.00%> (ø)
message/pool/message.go 75.63% <100.00%> (ø)
message/type.go 100.00% <100.00%> (+20.00%) ⬆️
udp/coder/coder.go 72.54% <100.00%> (+8.44%) ⬆️
...ent/limitParallelRequests/limitParallelRequests.go 86.95% <0.00%> (-5.80%) ⬇️
tcp/client.go 71.15% <0.00%> (-2.99%) ⬇️
net/dtlslistener.go 67.34% <0.00%> (-2.05%) ⬇️
dtls/server/server.go 77.03% <0.00%> (-1.46%) ⬇️
udp/client/conn.go 72.92% <0.00%> (+0.55%) ⬆️
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link

@mniestroj mniestroj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -28,3 +29,8 @@ func RandMID() int32 {
}
return int32(uint16(binary.BigEndian.Uint32(b)))
}

// ValidateMessageID validates a message id for UDP. (0 <= mid <= 65535)
func ValidateMessageID(mid int32) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ValidateMID would be more in line with the existing naming convention, but it's clear either way so I don't mind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed 👍

@@ -46,10 +45,10 @@ func (c *Coder) Encode(m message.Message, buf []byte) (int, error) {
|1 1 1 1 1 1 1 1| Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
if m.MessageID < 0 || m.MessageID > math.MaxUint16 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a test of Encode with the boundary values for messageID and type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@sonarcloud
Copy link

sonarcloud bot commented Jan 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@jkralik jkralik merged commit ec789f2 into master Jan 9, 2023
@jkralik jkralik deleted the jkralik/fix/upsert-mid branch January 9, 2023 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants