Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#6831 closed defect (fixed)

Fix behavior of round_to_power_of_2

Reported by: nickm Owned by:
Priority: Very Low Milestone: Tor: 0.2.4.x-final
Component: Core Tor/Tor Version:
Severity: Keywords: tor-relay
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

When called on a value greater than 1llu <<63, round_to_power_of_2 will try to compute 1llu <<64, which is undefined.

This shouldn't be happening, since we only call this function in one place related to memory allocation, and we shouldn't be trying to allocate exabits of data anyway.

Still, better to fix it than not.

Similar to #6827 ; found while looking for similar problematic shifts.

Child Tickets

Change History (9)

comment:1 Changed 8 years ago by nickm

Status: newneeds_review

Fix in branch bug6831 in my public repo.

comment:2 Changed 8 years ago by nickm

(oops; I meant "exabyte" in the description of this bug.)

comment:3 in reply to:  1 Changed 8 years ago by rransom

Replying to nickm:

Fix in branch bug6831 in my public repo.

s/positive power of 2/non-negative power of 2/

Other than that, looks good.

comment:4 Changed 8 years ago by nickm

I might have the wrong term; I meant to convey that it an never return 20; only 21 or higher.

comment:5 Changed 8 years ago by nickm

erg. Make that "It can never return 20 -- only 21 or higher."

comment:6 Changed 8 years ago by rransom

If round_to_power_of_2's input is 0, its output will be--- eeek, it is 2.

If round_to_power_of_2's input is 1, its output will be 1 (or 20).

comment:7 Changed 8 years ago by nickm

Resolution: fixed
Status: needs_reviewclosed

Yowza. Honestly, it seems smarter to fix this situation than to document it. Merged branch bug6831_v2, which makes the function do what you'd expect.

comment:8 Changed 8 years ago by nickm

Keywords: tor-relay added

comment:9 Changed 8 years ago by nickm

Component: Tor RelayTor
Note: See TracTickets for help on using tickets.