Repository navigation
net: prevent signed integer overflow in AddLocal nScore update - #34674
Closed
chriszeng1010 wants to merge 1 commit into
Closed
chriszeng1010 wants to merge 1 commit into
chriszeng1010 wants to merge 1 commit into
Conversation
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. |
frankomosh
reviewed
Feb 27, 2026
| LocalServiceInfo &info = it->second; | ||
| if (is_newly_added || nScore >= info.nScore) { | ||
| info.nScore = nScore + (is_newly_added ? 0 : 1); | ||
| info.nScore = is_newly_added ? nScore : SaturatingAdd(nScore, 1); |
Contributor
There was a problem hiding this comment.
Are there realistic scenarios where nScore equals INT_MAX here?
Author
There was a problem hiding this comment.
This is a consistency fix. The same overflow pattern was already fixed in SeenLocal() via #34028, nScore would need billions of AddLocal() calls on the same address.
Member
|
Was this LLM generated? What are the steps to test this? What is the output before and after the changes here? |
Author
Member
|
Thx, but LLM output is not accepted if the author can not properly explain, test or could have written the change themselves. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
AddLocal()is called for an address already in mapLocalHost, it increments nScore by 1. If nScore is at INT_MAX, this is signed integer overflow (undefined behavior).Use
SaturatingAddfromutil/overflow.hto cap at INT_MAX instead.This is the same class of bug addressed for
SeenLocal()in #34028, but in a different call site.