Commit ff1bf885 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

files: limit the number of attempts at climbing up the directory tree

Doing a chdir("..") will not fail when the root directory is reached,
and when getcwd() keeps failing too, we have no way of knowing when
to stop.  So, simply limit the number of attempted chdirs, to avoid
getting into an endless loop.

This avoids the hang in https://savannah.gnu.org/bugs/index.php?47659

.
Reported-by: default avatarChris Renshaw <osm0sis@outlook.com>
Signed-off-by: default avatarBenno Schulenberg <bensberg@justemail.net>
No related merge requests found
Showing with 5 additions and 4 deletions
+5 -4
......@@ -1409,6 +1409,8 @@ void do_insertfile_void(void)
* able to go there. */
char *get_full_path(const char *origpath)
{
int attempts = 0;
/* How often we've tried climing back up the tree. */
struct stat fileinfo;
char *d_here, *d_there, *d_there_file = NULL;
const char *last_slash;
......@@ -1422,11 +1424,10 @@ char *get_full_path(const char *origpath)
* current directory. */
d_here = getcwd(NULL, PATH_MAX + 1);
while (d_here == NULL) {
if (chdir("..") == -1)
break;
while (d_here == NULL && attempts < 20) {
IGNORE_CALL_RESULT(chdir(".."));
d_here = getcwd(NULL, PATH_MAX + 1);
attempts++;
}
/* If we succeeded, canonicalize it in d_here. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment