Actions
Bug #3250
closedgetcwd() succeeds even if the current directory no longer exists
Start date:
10/22/2020
Due date:
11/01/2020
% Done:
100%
Estimated time:
Description
The Dragonfly BSD getcwd(3) man page claims:
ERRORS
The getcwd() function will fail if:
...
[ENOENT] A component of the pathname no longer exists.
but this does not occur:
$ cat cwd_noent.c
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
char path255;
- /home/tony/dev/perl/git/dflybugs/testdir
FAIL: stat failed for path returned by getcwd: No such file or directory
$ uname -a
DragonFly 5.8-RELEASE DragonFly v5.8.3-RELEASE #10: Thu Sep 24 19:19:45 EDT 2020 root@www.shiningsilence.com:/usr/obj/home/justin/release/5_8/sys/X86_64_GENERIC x86_64
if (mkdir("testdir", 0700) < 0) {
perror("NA: mkdir");
exit(1);
}
if (chdir("testdir") < 0) {
perror("NA: chdir");
exit(1);
}
if (rmdir("../testdir") < 0) {
perror("NA: testdir");
exit(1);
}
/* getcwd() succeeds despite the directory no longer existing */
if (getcwd(path, sizeof(path))) {
struct stat st;
int rc = stat(path, &st);
printf("# %s\n", path);
if (rc < 0) {
perror("FAIL: stat failed for path returned by getcwd");
exit(1);
}
else {
printf("NA: directory I removed still exists\n");
}
}
else {
int err = errno;
printf("OK: getcwd failed\n");
if (err == ENOENT) {
printf("OK: ENOENT correctly set\n");
}
else {
printf("FAIL: bad errno %d\n", err);
exit(1);
}
}
return 0;
}
$ cc -ocwd_noent cwd_noent.c
$ ./cwd_noent
This came up from a failure in the perl test suite, our bug for this can be found at https://github.com/Perl/perl5/issues/16525
Updated by deef about 4 years ago
- Due date set to 11/01/2020
- Category changed from Userland to Kernel
- Status changed from New to Resolved
- % Done changed from 0 to 100
Thank you for detailed bug report. Fixed in commit d6853f97+ and MFCed to RELEASE_5_8 in commit 6e9a8bad+.
Actions