std.file functions and embedded NUL characters [CWE-158]
H. S. Teoh
hsteoh at qfbox.info
Thu Jul 31 21:34:36 UTC 2025
On Thu, Jul 31, 2025 at 09:25:44PM +0000, Doigt via Digitalmars-d wrote:
> On Thursday, 31 July 2025 at 20:45:14 UTC, kdevel wrote:
[...]
> > Other languages like D, perl or even Ada seem to let the embedded
> > NUL character silently truncate the filename. This poses a
> > considerable risk when the input to std.file functions is not
> > controlled by the program author [1]. E.g.
> >
> > rmdirRecurse ("/\0/home/user/subdir");
> >
> > [1] https://cwe.mitre.org/data/definitions/158.html
>
> Do you actually have a source or an example program that D actually does
> anything with the null terminator or are you talking out of your ass? D
> doesn't care about the null terminator and doesn't do anything with it.
This tone is uncalled for. OP is specifically pointing the issue with
passing NUL-containing strings to underlying OS calls. For example:
```
void main() {
auto fp = File("/tmp/x\0reallynow", "w");
// What's the filename of the created file?
}
```
T
--
Last night, I dreamed about my pet rabbits all lined up like in a parade, and hopping backwards.
Then I woke up and realized that it was my receding hare line!
More information about the Digitalmars-d
mailing list