WASI-SDK readlink() has invalid error handling
- Dominant language
- Perl
- Stars
- 3.9k
- Forks
- 213
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
I am posting this as an advisory notice so people can find it if they search for readlink(), I don't need it fixed.
POSIX says that if readlink() is applied to an actual file, not a link, it should return -1 and set errno to EINVAL (https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/readlink.html). In Wasi-SDK, it returns 3 and places the 3-character string "-22" in the buf, the second parameter to readlink().
This is a minimal test program to check the invalid behavior (run `touch testfile` and then the test program):
```
#include
#include
#include
int main(void)
{
const char *pathname = "testfile";
char buf[_POSIX_PATH_MAX];
ssize_t len;
if ((len = readlink (pathname, buf, sizeof (buf) - 1)) != -1)
{
buf[len] = 0;
fprintf(stderr, "DBG -- readlink() returned %zd\n", len);
fprintf(stderr, "and put %s in return buffer\n", buf);
return 1;
} else {
printf("readlink() returned correct error\n");
return 0;
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling and running the minimal C program with WASI-SDK after creating testfile, then compare readlink() behavior with the POSIX specification linked in the issue. The report is advisory and explicitly says no fix is needed, so a completed change is not defined by the payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, wasm
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100