Bug 21729 – rawRead derefences null pointer if invoked on closed File (segfault)

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

Comments

Comment #0 by kdevel — 2021-03-18T11:14:17Z
```n.d import std.stdio; void main () { File f; ubyte [1] u; auto n = f.rawRead (u); } ``` $ dmd -g n.d $ gdb ./n [...] (gdb) r [...] Program received signal SIGSEGV, Segmentation fault. 0xXXXXXXXXXXXXXXXX in std.stdio.File() (this=..., buffer=...) at [...]/dmd2/linux/bin64/../../src/phobos/std/stdio.d:1036 1036 immutable freadResult = trustedFread(_p.handle, buffer); (gdb) p _p $1 = (struct std.stdio.File.Impl *) 0x0
Comment #1 by bugzilla — 2021-03-18T14:14:57Z
I think, before doing this "trustedFread" in (currently) line 1057, there needs to be an `enforce(_p !is null, some message)`. But I'm not firm enough in std.stdio, so I don't want to file a fixing PR. Might fix 21728 too.
Comment #2 by dlang-bot — 2021-05-01T14:47:58Z
@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 21729 - rawRead derefences null pointer if invoked on closed File (segfault) https://github.com/dlang/phobos/pull/8025
Comment #3 by dlang-bot — 2021-05-04T10:02:57Z
dlang/phobos pull request #8025 "Fix Issues 21728, 21729 and 21730 (check for open file, before using trustedFread)" was merged into stable: - 3b501e1ddca1b144234a0fa27d6dc7109b7c9aa7 by berni44: Fix Issue 21729 - rawRead derefences null pointer if invoked on closed File (segfault) https://github.com/dlang/phobos/pull/8025