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

validate max_allowed_packet on the client side #84

Merged
merged 4 commits into from
Jun 7, 2023

Conversation

matthewd
Copy link
Contributor

@matthewd matthewd commented Jun 6, 2023

This is another take on #79, incorporating lessons learned while working on #81.

Copy link
Contributor

@brianmario brianmario left a comment

Choose a reason for hiding this comment

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

Nice and clean

{
if (builder->packet_length > max_length) {
return TRILOGY_MAX_PACKET_EXCEEDED;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch here 👍

* max_length - The new maximum packet length to set
*
* Return values:
* TRILOGY_OK - The maximum packet length was set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor nit that you don't really have to do, but would you mind indenting from - to line up with the one below, like the rest of the comments? I never used to do stuff like this, but gofmt changed my life for better or worse 😆

I guess the rest of the comments above where TRILOGY_MAX_PACKET_EXCEEDED was added could use it as well so everything lines up nicely. But again, no big deal if that's annoying ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah, this is a bit of an ugly floater. I deliberately didn't want to give up that much horizontal space by aligning everything to the new very-long name, but now this line is only aligned with the separate preceding blocks. 😕

I see I was also needlessly careless on the wrapped indentation below -- I copied across the misalignment from buffer.h, without noticing this is the first instance in this file.

I think we just need to do a bit of a general sweep... I think the alignment was a lot more consistent before one of the renames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed this one, and tidied the wrapping on the others, but couldn't bring myself to drag the other descriptions over that far. 🤷🏻‍♂️

Makefile Outdated
ifeq ($(UNAME_S), Darwin)
CFLAGS += "-I$(shell brew --prefix openssl@1.1)/include"
LDFLAGS += "-L$(shell brew --prefix openssl@1.1)/lib"
else
Copy link
Contributor

Choose a reason for hiding this comment

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

In a perfect world this could be in its own pull, but I was getting sick of adding these myself locally when compiling so I'm personally all good with it going in with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this had started life on its own branch; rebased out now and I'll push it separately.

@matthewd
Copy link
Contributor Author

matthewd commented Jun 6, 2023

@brianmario thanks for checking this out! While I've got you -- what do you think of s/TRILOGY_MAX_PACKET_LEN/TRILOGY_MAX_FRAGMENT_LEN/ or something?

Per the discussion in #79 (and my repeated confusion in figuring this out 😅), while those chunks certainly meet a reasonable definition of a packet, I feel like we might be better off using a different term internally. From a quick search, I think even other instances within the codebase are already using "packet" to refer to the potentially-multi-part total message.

@kamil-gwozdz kamil-gwozdz mentioned this pull request Jun 6, 2023
Closed
@brianmario
Copy link
Contributor

@matthewd I'd definitely be in favor of renaming that constant. At the time, the difference between a "packet" and a "frame" (or whatever other term might be used for the segments of data) didn't matter as much. But I think it makes sense to rename either as part of this pull or a follow up before a new release is tagged 👍

test/builder_test.c Outdated Show resolved Hide resolved
matthewd and others added 4 commits June 8, 2023 03:22
Sending an over-limit packet will cause the server to drop the
connection; by enforcing the limit on the client, we can fail in a way
that keeps the connection usable.

Co-authored-by: Kamil Gwóźdź <kamil-gwozdz@github.com>
We don't really care what's in there, but this is more hygienic, and
will likely keep Valgrind happier.
Co-authored-by: Kamil Gwóźdź <kamil-gwozdz@github.com>
@matthewd matthewd merged commit d7da184 into trilogy-libraries:main Jun 7, 2023
@matthewd matthewd deleted the max-size-v4 branch June 7, 2023 19:11
@matthewd matthewd mentioned this pull request Jun 7, 2023
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.

4 participants