mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
fix infinite loop/oom when cwd longer then 1024
The code reads cwd into a buffer, which is expanded while errno is ERANGE, with the intent of growing the buffer until the path fits. While getcwd will set errno on error, it will not reset it once the path fits into the buffer. So to not get an infinite loop once errno is ERANGE, we need to make sure to reset errno, such that the loop behaves as expected.
This commit is contained in:
parent
736328ab6b
commit
bfabc5450b
1 changed files with 1 additions and 1 deletions
2
main.c
2
main.c
|
|
@ -552,10 +552,10 @@ main(int argc, char *const *argv)
|
|||
char *_cwd = NULL;
|
||||
|
||||
if (cwd == NULL) {
|
||||
errno = 0;
|
||||
size_t buf_len = 1024;
|
||||
do {
|
||||
_cwd = xrealloc(_cwd, buf_len);
|
||||
errno = 0;
|
||||
if (getcwd(_cwd, buf_len) == NULL && errno != ERANGE) {
|
||||
LOG_ERRNO("failed to get current working directory");
|
||||
goto out;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue