[Bug 53677] New: invalid O_WRONLY read sets errno=EACCES instead of EBADF
https://bugs.winehq.org/show_bug.cgi?id=53677 Bug ID: 53677 Summary: invalid O_WRONLY read sets errno=EACCES instead of EBADF Product: Wine Version: 7.17 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown Assignee: wine-bugs(a)winehq.org Reporter: xantares09(a)hotmail.com Distribution: --- Created attachment 73089 --> https://bugs.winehq.org/attachment.cgi?id=73089 minimal testcase I noticed that an incorrect read from a file in write-only mode can result in errno to be set to EACCES instead of EBADF that is returned on native linux or on windows (either msvc or cross-compiled mingw), see attached testcase $ x86_64-w64-mingw32-gcc main.c $ wine a.exe EBADF=9 EACCES=13 errno=13 errno should be EBADF whereas on native linux or windows:
a EBADF=9 EACCES=13 errno=9
tested with latest 7.17 on archlinux but also happens with 6.0 on ubuntu jammy -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Distribution|--- |ArchLinux -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #1 from xantares <xantares09(a)hotmail.com> --- Created attachment 73132 --> https://bugs.winehq.org/attachment.cgi?id=73132 executable file matching testcase source -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #2 from xantares <xantares09(a)hotmail.com> --- here is the testcase: ``` #include <stdio.h> #include <errno.h> #include <sys/stat.h> #include <fcntl.h> #ifndef _WIN32 #include <unistd.h> #define POSIX(call) call #else #include <io.h> #define POSIX(call) _##call #endif int main() { // create a file a write into if const char * path = "test-file"; FILE* fp = fopen(path, "w"); fputs("long live the king", fp); fclose(fp); // open file in write-only mode int oflag = POSIX(O_WRONLY); #ifndef _WIN32 int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; #else int perm = _S_IREAD | _S_IWRITE; #endif int fd = POSIX(open(path, oflag, perm)); if (fd < 0) { printf("ERROR open failed\n"); return 1; } // it should fail to read char buffer = 0; unsigned count = 1; int result = POSIX(read(fd, &buffer, count)); if (result >= 0) { printf("ERROR read should fail\n"); return 1; } // compare error code mingw->EACCES, linux->EBADF printf("EBADF=%d EACCES=%d\n", EBADF, EACCES); printf("errno=%d\n", errno); if (errno != EBADF) { printf("errno should be EBADF\n"); return 1; } return 0; } ``` -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |austinenglish(a)gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, source -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #3 from xantares <xantares09(a)hotmail.com> --- I discussed this previously on the mingw mailing list: https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/CALK-3m%... -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |julliard(a)winehq.org -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|7.17 |7.18 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Piotr Caban <piotr.caban(a)gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|-unknown |msvcrt CC| |piotr.caban(a)gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Fabian Maurer <dark.shadow4(a)web.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dark.shadow4(a)web.de Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #4 from Fabian Maurer <dark.shadow4(a)web.de> --- Confirming. Not sure how to best fix it though. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #5 from xantares <xantares09(a)hotmail.com> --- thanks, at least I was right -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #6 from Piotr Caban <piotr.caban(a)gmail.com> --- It should be fixed by 3fd47b4663af18d815f85f50c9f343bb6aca7066. Please retest. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #7 from Fabian Maurer <dark.shadow4(a)web.de> --- (In reply to Piotr Caban from comment #6)
It should be fixed by 3fd47b4663af18d815f85f50c9f343bb6aca7066. Please retest.
Huh, is the file being opened read only really the only case where we can get ERROR_ACCESS_DENIED? I thought there might be others... -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #8 from Piotr Caban <piotr.caban(a)gmail.com> --- (In reply to Fabian Maurer from comment #7)
Huh, is the file being opened read only really the only case where we can get ERROR_ACCESS_DENIED? I thought there might be others...
I'm also not sure if the change is correct but there's a big chance it is. Native sets errno, doserrno and GetLastError to EBADF and ERROR_ACCESS_DENIED. Since it's very unlikely that SetLastError is called directly in msvcrt I assume that ReadFile is called. Msvcrt does not store open mode of fd, one would need to call e.g. NtQueryInformationFile to distinguish between ERROR_ACCESS_DENIED errors. Probably the only way of checking it is to create a custom device handle that will return ERROR_ACCESS_DENIED on read. Since it's hard to test and is an unlikely use case I didn't test it. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #9 from xantares <xantares09(a)hotmail.com> --- thanks a lot, I'll definetely test this when next version hits the repo -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #10 from xantares <xantares09(a)hotmail.com> --- ok with 7.21 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 xantares <xantares09(a)hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED --- Comment #11 from xantares <xantares09(a)hotmail.com> --- closing -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Gijs Vermeulen <gijsvrm(a)gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|CLOSED |RESOLVED Fixed by SHA1| |3fd47b4663af18d815f85f50c9f | |343bb6aca7066 --- Comment #12 from Gijs Vermeulen <gijsvrm(a)gmail.com> --- No need to close, FIXED bug reports are closed automatically when the next release goes live. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 --- Comment #13 from xantares <xantares09(a)hotmail.com> --- hello, Similarly I found another incorrect error code: https://bugs.winehq.org/show_bug.cgi?id=53950 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Alexandre Julliard <julliard(a)winehq.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED --- Comment #14 from Alexandre Julliard <julliard(a)winehq.org> --- Closing bugs fixed in 7.22. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Michael Stefaniuc <mstefani(a)winehq.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |7.0.x -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=53677 Michael Stefaniuc <mstefani(a)winehq.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|7.0.x |--- --- Comment #15 from Michael Stefaniuc <mstefani(a)winehq.org> --- Drop 7.0.x target milestone from bugs that didn't make it. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (1)
-
WineHQ Bugzilla