diff --git a/ChangeLog b/ChangeLog index 92a629efc00e827a76a89f74f93963717f402cc8..fdf6fc7838bd77935e509c8ee40e71e87288edc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * src/files.c (read_file): Free not just the struct but also the data it contains, and also when it is the first and only line. This fixes Savannah bug #47153 reported by Mike Frysinger. + * src/files.c (get_full_path): Avoid losing a buffer when getcwd() + fails. This fixes Savannah bug #47129 reported by Mike Frysinger. 2016-02-14 Benno Schulenberg <bensberg@justemail.net> * src/search.c (do_replace_loop): Make iterating through replacement diff --git a/src/files.c b/src/files.c index 2fe1be905d872639ccfd440ff3acbc0c62e69af1..afb499a0eb7a62336bf4807795506a36a1cbcfcd 100644 --- a/src/files.c +++ b/src/files.c @@ -1413,14 +1413,13 @@ char *get_full_path(const char *origpath) /* Get the current directory. If it doesn't exist, back up and try * again until we get a directory that does, and use that as the * current directory. */ - d_here = charalloc(PATH_MAX + 1); - d_here = getcwd(d_here, PATH_MAX + 1); + d_here = getcwd(NULL, PATH_MAX + 1); while (d_here == NULL) { if (chdir("..") == -1) break; - d_here = getcwd(d_here, PATH_MAX + 1); + d_here = getcwd(NULL, PATH_MAX + 1); } /* If we succeeded, canonicalize it in d_here. */ @@ -1481,8 +1480,7 @@ char *get_full_path(const char *origpath) free(d_there); /* Get the full path. */ - d_there = charalloc(PATH_MAX + 1); - d_there = getcwd(d_there, PATH_MAX + 1); + d_there = getcwd(NULL, PATH_MAX + 1); /* If we succeeded, canonicalize it in d_there. */ if (d_there != NULL) {