-
Notifications
You must be signed in to change notification settings - Fork 602
ICP: bound-check ICP_QUERY; register read after init #2220
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -461,7 +461,6 @@ HttpRequest * | |||||||||||||
| icpGetRequest(char *url, int reqnum, int fd, Ip::Address &from) | ||||||||||||||
| { | ||||||||||||||
| if (strpbrk(url, w_space)) { | ||||||||||||||
| url = rfc1738_escape(url); | ||||||||||||||
| icpCreateAndSend(ICP_ERR, 0, rfc1738_escape(url), reqnum, 0, fd, from, nullptr); | ||||||||||||||
| return nullptr; | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -481,8 +480,18 @@ doV2Query(int fd, Ip::Address &from, char *buf, icp_common_t header) | |||||||||||||
| int rtt = 0; | ||||||||||||||
| int src_rtt = 0; | ||||||||||||||
| uint32_t flags = 0; | ||||||||||||||
| /* We have a valid packet */ | ||||||||||||||
| char *url = buf + sizeof(icp_common_t) + sizeof(uint32_t); | ||||||||||||||
| /* Ensure QUERY has space for the 32-bit field and at least one URL byte. */ | ||||||||||||||
| const auto hdr = sizeof(icp_common_t); | ||||||||||||||
| const auto qhdr = hdr + sizeof(uint32_t); | ||||||||||||||
|
Comment on lines
+484
to
+485
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a size. Please indicate that in the variable name.
Suggested change
related lines will need adjusting to match |
||||||||||||||
| const auto pkt_len = static_cast<size_t>(header.length); | ||||||||||||||
| if (pkt_len <= qhdr) { | ||||||||||||||
| debugs(12, 3, "icpHandleIcpV2: short ICP_QUERY from " << from); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or (if we have already checked header size) perhaps
Suggested change
"ICP" context will be added to output by debugs() because this file name is "icp_v2.cc". Other related messages already use "too small" terminology. I do not insist on it, but the message should indicate that there is a problem here. |
||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
| /* Guarantee an in-bounds NUL terminator for any downstream C-string use. */ | ||||||||||||||
| buf[pkt_len - 1] = '\0'; | ||||||||||||||
| auto url = buf + qhdr; | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, from); | ||||||||||||||
|
|
||||||||||||||
| if (!icp_request) | ||||||||||||||
|
|
@@ -737,8 +746,6 @@ icpIncomingConnectionOpened(Ipc::StartListeningAnswer &answer) | |||||||||||||
| if (!Comm::IsConnOpen(conn)) | ||||||||||||||
| fatal("Cannot open ICP Port"); | ||||||||||||||
|
|
||||||||||||||
| Comm::SetSelect(conn->fd, COMM_SELECT_READ, icpHandleUdp, nullptr, 0); | ||||||||||||||
|
|
||||||||||||||
| for (const wordlist *s = Config.mcast_group_list; s; s = s->next) | ||||||||||||||
| ipcache_nbgethostbyname(s->key, mcastJoinGroups, nullptr); // XXX: pass the conn for mcastJoinGroups usage. | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -750,6 +757,8 @@ icpIncomingConnectionOpened(Ipc::StartListeningAnswer &answer) | |||||||||||||
| icpOutgoingConn = conn; | ||||||||||||||
| debugs(12, DBG_IMPORTANT, "Sending ICP messages from " << icpOutgoingConn->local); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Comm::SetSelect(conn->fd, COMM_SELECT_READ, icpHandleUdp, nullptr, 0); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
AFAICT, the above allegation is misleading or incorrect: Calling Official code is structured/ordered slightly better IMO. Please undo this change unless my analysis above is flawed. It is probably a good idea to add a "icpOutgoingConn is set" assertion to icpHandleUdp(). AFAICT, we have similar assertions elsewhere, and existing module initialization code is trying to uphold that invariant (albeit clumsily; if you want to improve that, I would consider replacing the above Please do not forget to update PR title/description after addressing this change request. |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
||||||||||||||
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.
doV2Query() caller validates that the query was not truncated:
Moreover, doV2Query grand-caller -- icpHandleUdp() -- unconditionally terminates the buffer:
buf[len] = '\0';If the above analysis is correct, then neither alleged truncation nor lack of URL termination are real. If you agree, please adjust this PR metadata and code accordingly.