-
Notifications
You must be signed in to change notification settings - Fork 493
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
Replace usage addrinfo with Ip::Address in icmp4 #1789
base: master
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
As we discussed, aim of this PR is try to remove usage of This pr related to #1671 |
Feel free to add some comments and suggestions, since, honestly, I've lack of knowledge and experience with such type things. |
from->ai_addr, | ||
&from->ai_addrlen); | ||
reinterpret_cast<sockaddr*>(&from), | ||
0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The horrible casting aside, this change violates recvfrom() call intent (and possibly API) by supplying a nil pointer to address size (disguised as integer 0
): "the caller should initialize [addrlen memory] before the call to the size of the buffer associated with src_addr"
To move this PR forward, I suggest:
- Test changes before posting a PR (or PR updates).
- Remove reinterpret_cast. If you need a sockaddr object, use a local sockaddr variable .
- Read recvfrom() documentation and understand why that specific system call is used here.
- Supply a non-nil addrlen pointer to recvfrom(). Use another local variable of the right type for this addrlen. The value of that variable will depend on how your solution provides the memory for the address, but it will not be zero.
- Add a check for recvfrom() truncating the address, report an error if it did, and do not use the truncated address.
- Do not use std::move() unless the code does not compile without it (its use is always a red flag in Squid code, but there are legitimate use cases, of course): It is difficult to use std::move() correctly, it is usually a bad idea to use it, and it is probably not going to be needed in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could assume, that
Ip::Address
is byte compatible with
addrinfo
and could be used directly instead of it.
This assumption is false. IPv4 and IPv6 different in byte sizes. While the field layout of sockaddr
group of structures matches, the address fields differ in size and format.
@@ -156,7 +156,7 @@ void | |||
Icmp4::Recv(void) | |||
{ | |||
int n; | |||
struct addrinfo *from = nullptr; | |||
Ip::Address from; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from
should be of type sockaddr_storage
and empty.
Ip::Address from; | |
sockaddr_storage from; | |
memset(&from, 0, sizeof(from)); |
Also, these lines should be down just before first-use, where the recvfrom()
is called.
return; | ||
} | ||
|
||
preply.from = *from; | ||
preply.from = std::move(from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preply.from = std::move(from); | |
preply.from = from; |
Replace usage of addrinfo in icmp4 with more
appropriate way