Skip to content

gfileutils: Fix potential integer overflow in g_get_current_dir()

Philip Withnall requested to merge pwithnall/glib:98-current-path into main

In practice, this will never happen.

If getcwd() returns ERANGE whenever the working directory is ≥ PATH_MAX, though, the previous implementation of the loop would run until max_len == G_MAXULONG, and would then overflow when adding 1 to it for a nul terminator in the allocation.

Avoid that problem by always keeping buffer_len as a power of two, and reserving space for the nul terminator by subtracting 1 for the length passed to getcwd().

Signed-off-by: Philip Withnall pwithnall@endlessos.org

Fixes: #98 (closed)

Closes #98 (closed)

Merge request reports