Documentation states pmode argument is needed when _O_CREAT is used.
``` dlls/msvcrt/tests/i386-windows/msvcrt_test.exe misc ================================================================= ==544==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x0031e7c0 at pc 0x7a1ed844 bp 0x0031e734 sp 0x0031e730 READ of size 4 at 0x0031e7c0 thread T0 0234:fixme:msvcrt:_set_abort_behavior _WRITE_CALL_REPORTFAULT unhandled 0234:fixme:file:server_get_file_info Unsupported info class e #0 0x7a1ed843 in _open .../wine/dlls/msvcrt/file.c:2663:13 #1 0x00482c05 in test__popen .../wine/dlls/msvcrt/tests/misc.c:367:10 #2 0x00482c05 in func_misc .../wine/dlls/msvcrt/tests/misc.c:767:5 #3 0x0052909e in run_test .../wine/include/wine/test.h:765:5 #4 0x0052909e in main .../wine/include/wine/test.h:884:12 #5 0x0052ae2b in mainCRTStartup .../wine/dlls/msvcrt/crt_main.c:58:11 #6 0x7bb8ea3f in BaseThreadInitThunk (C:\windows\system32\kernel32.dll+0x7b80ea3f) #7 0x7bd0ce82 in call_thread_func_wrapper (C:\windows\system32\ntdll.dll+0x7bc0ce82) #8 0x7bd404e4 in call_thread_func .../wine/dlls/ntdll\signal_i386.c:524:9
Address 0x0031e7c0 is located in stack of thread T0 at offset 0 in frame #0 0x0047f73f in func_misc .../wine/dlls/msvcrt/tests/misc.c:742
This frame has 15 object(s): [16, 20) 'num.i' (line 682) [32, 36) 'ctx.i' (line 684) [48, 52) 'key.i' (line 685) [64, 464) 'tab.i' (line 440) [528, 1048) 'small_sort.i' (line 442) [1184, 1704) 'small_sort2.i' (line 442) [1840, 2360) 'quick_sort.i' (line 442) [2496, 3520) 'buf.i270' (line 362) [3648, 3652) 'out.i115' (line 260) [3664, 3668) 'out.i91' (line 235) [3680, 3936) 'buf.i53' (line 189) [4000, 4104) 'out.i' (line 158) [4144, 4148) 'rand.i' (line 77) [4160, 5184) 'buf.i' (line 347) [5312, 5316) 'arg_v' (line 744) HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork (longjmp, SEH and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-underflow .../wine/dlls/msvcrt/file.c:2663:13 in _open Shadow bytes around the buggy address: 0x0031e500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0031e580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0031e600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0031e680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0031e700: 00 00 00 00 00 00 00 00 f1 f1 04 f3 00 00 00 00 =>0x0031e780: 00 00 00 00 00 00 00 00[f1]f1 f8 f2 f8 f2 f8 f2 0x0031e800: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 0x0031e880: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 0x0031e900: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 0x0031e980: f8 f8 f2 f2 f2 f2 f2 f2 f2 f2 f8 f8 f8 f8 f8 f8 0x0031ea00: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==544==ABORTING ```
Today I was not able to get ASan triggered on this, but I guess this may be related to me using currently `-O1` instead of previously `-O2` and some more different compile options. But I thought this might still worth submitting.
From: Bernhard Übelacker bernhardu@mailbox.org
Documentation states pmode argument is needed when _O_CREAT is used. --- dlls/msvcrt/tests/misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/tests/misc.c b/dlls/msvcrt/tests/misc.c index 7b54b3aeb88..02e68610b20 100644 --- a/dlls/msvcrt/tests/misc.c +++ b/dlls/msvcrt/tests/misc.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <math.h> #include <process.h> +#include <sys/stat.h>
static inline BOOL almost_equal(double d1, double d2) { if(d1-d2>-1e-30 && d1-d2<1e-30) @@ -364,7 +365,7 @@ static void test__popen(const char *name)
tempf = _tempnam(".", "wne"); ok(tempf != NULL, "_tempnam failed\n"); - fd = _open(tempf, _O_CREAT | _O_WRONLY); + fd = _open(tempf, _O_CREAT | _O_WRONLY, _S_IWRITE); ok(fd != -1, "open failed\n");
sprintf(buf, ""%s" misc popen %d", name, fd);
This merge request was approved by Piotr Caban.