std::bad_alloc in CoinFindDirSeparator() when current working directory doesn't exist
- Dominant language
- C++
- Stars
- 53
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
On Linux (and possibly other platforms), when the current directory does not exist, then `getcwd()` always fails (and gives `errno = ENOENT`), meaning that the function enters an infinite loop trying to allocate larger and larger buffers until `size` overflows into a negative number leading to a `std::bad_alloc`.
https://github.com/coin-or/CoinUtils/blob/ab8cedf4cf4a163725251666f87276e44f492e81/src/CoinHelperFunctions.hpp#L952-L969
This causes Cbc and many other coin programs to crash on startup since they call `CoinFindDirSeparator()`.
I'm not sure why the directory separator needs to be found in this way (and not just use defines to set it to backslash on Windows and forward slash everywhere else).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/CoinHelperFunctions.hpp at CoinFindDirSeparator(), especially the getcwd() buffer-growth loop linked in the issue. Reproduce the failure from a process whose current directory has been removed, then inspect how the existing callers use the result. Done means the function no longer loops until allocation failure or crashes when getcwd() returns ENOENT.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100