X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fat-func.c;h=4e5ba2f7ed5d75b5ef7e02e45d09e2c7b4fb91d2;hb=100bccc49b23e2674a660653fa8036af3730f564;hp=75c80d3c9f5c1cd9b994ee948e0d280a0fe40e4e;hpb=cb7317d75af2de40fecdd949e3fb11a85b09e10a;p=gnulib.git diff --git a/lib/at-func.c b/lib/at-func.c index 75c80d3c9..4e5ba2f7e 100644 --- a/lib/at-func.c +++ b/lib/at-func.c @@ -89,6 +89,15 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) if (save_cwd (&saved_cwd) != 0) openat_save_fail (errno); + if (0 <= fd && fd == saved_cwd.desc) + { + /* If saving the working directory collides with the user's + requested fd, then the user's fd must have been closed to + begin with. */ + free_cwd (&saved_cwd); + errno = EBADF; + return -1; + } if (fchdir (fd) != 0) {