Bug 21728 – rawRead calls fread with NULL if invoked on closed readEnd of Pipe (segfault)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2021-03-18T10:59:33Z
Last change time
2021-05-04T10:02:55Z
Keywords
pull
Assigned to
No Owner
Creator
kdevel

Comments

Comment #0 by kdevel — 2021-03-18T10:59:33Z
```n1.d import std.stdio; import std.process; void main () { auto p = pipe (); p.readEnd.close; ubyte [1] u; auto n = p.readEnd.rawRead (u); } ``` $ dmd -g n1.d $ gdb ./n1 [...] (gdb) r [...] Program received signal SIGSEGV, Segmentation fault. 0xXXXXXXXXXXXXXXXX in fread () from /lib64/libc.so.6 [...] (gdb) bt #0 0xXXXXXXXXXXXXXXXX in fread () from /lib64/libc.so.6 #1 0xXXXXXXXXXXXXXXXX in std.stdio() (obj=..., f=0x0) at [...]/dmd2/linux/bin64/../../src/phobos/std/stdio.d:4383 #2 0xXXXXXXXXXXXXXXXX in std.stdio.File() (this=..., buffer=...) at [...]/dmd2/linux/bin64/../../src/phobos/std/stdio.d:1036 #3 0xXXXXXXXXXXXXXXXX in D main () at n1.d:9 [...] fread is called with a null ptr as FILE*. It seems that trustedFwrite may be also affected. Problem turned up in in http://forum.dlang.org/thread/[email protected]
Comment #1 by dlang-bot — 2021-05-01T14:47:56Z
@berni44 created dlang/phobos pull request #8025 "Fix Issues 21728, 21729 and 21730 (check for open file, before using trustedFread)" fixing this issue: - Fix Issue 21728 - rawRead calls fread with NULL if invoked on closed readEnd of Pipe (segfault) https://github.com/dlang/phobos/pull/8025
Comment #2 by dlang-bot — 2021-05-04T10:02:55Z
dlang/phobos pull request #8025 "Fix Issues 21728, 21729 and 21730 (check for open file, before using trustedFread)" was merged into stable: - 5511155cccd931e7e9d334430377dc246a3052bb by berni44: Fix Issue 21728 - rawRead calls fread with NULL if invoked on closed readEnd of Pipe (segfault) https://github.com/dlang/phobos/pull/8025