std.file functions and embedded NUL characters [CWE-158]

kdevel kdevel at vogtner.de
Fri Aug 1 11:02:37 UTC 2025


On Friday, 1 August 2025 at 00:11:51 UTC, Steven Schveighoffer 
wrote:
> [...]
> If we checked for mid-string zero terminators on all calls to 
> `toStringz`, we would kill performance where mostly it isn't 
> necessary (this is only important if you don't trust where the 
> data came from. This would lead to a different sort of problem 
> ("How come D/C interop is so slow!?")

This is a strawman. I am writing about file system functions! 
Furthermode in the case of `std.file.rename` `toStringz` is not 
even called. What is used to convert to `char *` seems to be the 
highly interesting template `tempCString` in 
`std.internal.cstring`.

And of course a library should not assert, nor exit nor ignore 
the error, but make it handleable:

```
#!/usr/bin/python

def myfun (filename):
    open (filename, 'w')

try:
    myfun ("a\0c")
except TypeError:
    print ("error occurred")
#   raise
```


More information about the Digitalmars-d mailing list