The function RaiseFileDescriptorLimit returns an integer, but the returned value limitFD.rlim_cur (rlim_t) can be of type unsigned long long in some systems. This can lead to an overrun and subsequently to an error in the calling functions. To prevent that, it has to be checked if the value of rlim_cur exceeds the integer boundaries. If so the rlim_cur will be set to the maximum integer value.
util: check integer overrun in RaiseFileDescriptorLimit #21434
pull sebastianrapp wants to merge 1 commits into bitcoin:master from sebastianrapp:fdlimit changing 1 files +2 −0-
sebastianrapp commented at 9:24 AM on March 14, 2021: none
-
Check integer overrun in RaiseFileDescriptorLimit 267f7ba0b7
- fanquake added the label Utils/log/libs on Mar 14, 2021
-
practicalswift commented at 4:25 PM on March 15, 2021: contributor
Warm welcome as a contributor @sebastianrapp!
Interesting find! Can you describe how to reproduce the issue locally (what OS, what commands to issue, etc.)?
May I ask how you found this issue? It is always interesting to know.
-
sebastianrapp commented at 7:00 PM on March 15, 2021: none
Thank you very much. I was using macOS Big Sur (version 11.2.1) to reproduce this issue. Here I just need to run bitcoind and got the error message "Init: Not enough file descriptors available." So to be honest I was wondering why this issues was not observed before as this is a pretty straightforward use case, right. So maybe I have any special setting in my system of which I am currently not aware.
-
practicalswift commented at 8:49 AM on March 17, 2021: contributor
I don't have any Mac around to test on unfortunately: anyone running macOS who is able to reproduce this?
-
laanwj commented at 12:05 PM on March 17, 2021: member
It is kind of strange, as functions such as
openreadwritereturn or take anint>= 0 there would be no possible reason for there ever to be more than 2**31 file descriptors, so I cannot see the rationale of using a larger type for the limit. That said if this is necessary on some platforms it's necessary.Edit: well strictly if you want to use file descriptor 0x7fff_ffff you do need a type that can represent 0x8000_0000 which is > int … using that one extra fd doesn't seem worth the potential edge cases introduced by making this function return a different type though :smile:
-
fanquake commented at 3:50 PM on March 24, 2022: member
So maybe I have any special setting in my system of which I am currently not aware.
Given this is clearly something that no-one else is running into (there are many developers and users running bitcoind on macOS), I don't think we are going to merge this as-is. Probably a long-shot, but if you can provide any further information that may make it clearer as to why it's happening on your system, we could follow up. However I'm going to close this PR for now.
- fanquake closed this on Mar 24, 2022
- DrahtBot locked this on Mar 24, 2023