Potential integer overflow in bandwidth throttling timing calculation #68
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
In
src/shared/protocol.clines 37-57, the bandwidth throttling useslong longfor timing calculations:If
clock_gettime(CLOCK_MONOTONIC, ...)is called infrequently (minutes or hours apart), thetv_secdifference multiplied by 1 billion could overflowlong long(max ~9.2e18). At ~300 years of difference, the multiply alone would overflow. While unlikely in practice, a long-running transfer paused for a very long time could trigger this.Additionally, the token refill calculation on line 41:
Uses floating point in a timing-sensitive code path, and
doublemay lose precision for very large values ofio_bwlimit * elapsed_ns.Location
src/shared/protocol.c:37-57Suggested Fix
Severity
Low
Category
Quality