Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error code returned by some wasi fs syscalls for a non-existent file #2672

Merged
merged 2 commits into from
Nov 9, 2021

Conversation

kateinoigakukun
Copy link
Contributor

@kateinoigakukun kateinoigakukun commented Nov 9, 2021

Description

Currently, wasmer's WASI implementation returns EINVAL when a caller gives non-existent file path as a parameter.

But EINVAL should not be returned in such case and should return ENOENT instead according to POSIX.

This change affects to:

  • path_filestat_get
  • path_filestat_set_times
  • path_link
  • path_open
  • path_readlink
  • path_remove_directory
  • path_unlink_file

You can reproduce this issue by the following code

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

int main(void) {
  int ret = open("/nonexist", O_RDONLY);
  if (ret < 0) {
    int e = errno;
    perror("got error");
    printf("errno = %d\n", e);
  }
  printf("ret = %d\n", ret);
  return 0;
}
$ # expected result
$ wasmtime run path_open.wasm  --mapdir /::./
got error: No such file or directory
errno = 44
ret = -1

$ # with the latest build of wasmer master branch
$ wasmer run path_open.wasm  --mapdir /::./
got error: Invalid argument
errno = 28
ret = -1

Review

  • Add a short description of the change to the CHANGELOG.md file

EINVAL should not be returned when a path name doesn't exist and should
return ENOENT instead according to POSIX.

This change affects to:

- path_filestat_get
- path_filestat_set_times
- path_link
- path_open
- path_readlink
- path_remove_directory
- path_unlink_file
@ptitSeb ptitSeb requested a review from Amanieu November 9, 2021 08:57
@Amanieu
Copy link
Contributor

Amanieu commented Nov 9, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 9, 2021

@bors bors bot merged commit 01842f3 into wasmerio:master Nov 9, 2021
@kateinoigakukun kateinoigakukun deleted the katei/fix-path-open-err branch November 9, 2021 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants