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
  1. sebastianrapp commented at 9:24 AM on March 14, 2021: none

    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.

  2. Check integer overrun in RaiseFileDescriptorLimit 267f7ba0b7
  3. fanquake added the label Utils/log/libs on Mar 14, 2021
  4. 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.

  5. 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.

  6. 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?

  7. laanwj commented at 12:05 PM on March 17, 2021: member

    It is kind of strange, as functions such as open read write return or take an int >= 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:

  8. 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.

  9. fanquake closed this on Mar 24, 2022

  10. DrahtBot locked this on Mar 24, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me