From: Benno Schulenberg Date: Mon, 15 Feb 2016 16:24:39 +0000 (+0000) Subject: Avoiding the loss a buffer when getcwd() fails. X-Git-Tag: v2.5.3~33 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=706f01422dd5c6f12ca3d740f1bc64d20b8119c9;p=nano.git Avoiding the loss a buffer when getcwd() fails. This fixes Savannah bug #47129 reported by Mike Frysinger. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5647 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 92a629ef..fdf6fc78 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 * src/search.c (do_replace_loop): Make iterating through replacement diff --git a/src/files.c b/src/files.c index 2fe1be90..afb499a0 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) {