Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::bad_alloc in CoinFindDirSeparator() when current working directory doesn't exist #150

Open
cyderize opened this issue Feb 28, 2021 · 0 comments

Comments

@cyderize
Copy link

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.

inline char CoinFindDirSeparator()
{
int size = 1000;
char *buf = 0;
while (true) {
buf = new char[size];
if (getcwd(buf, size))
break;
delete[] buf;
buf = 0;
size = 2 * size;
}
// if first char is '/' then it's unix and the dirsep is '/'. otherwise we
// assume it's dos and the dirsep is '\'
char dirsep = buf[0] == '/' ? '/' : '\\';
delete[] buf;
return dirsep;
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant