Merge pull request #5049 from Burgos/fix-17102

fix issue 17102 - Don't pass null to strlen in std.file.cenforce
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
This commit is contained in:
The Dlang Bot 2017-01-21 18:48:11 +01:00 committed by GitHub
commit c6d33505dc

View file

@ -180,7 +180,7 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
import core.stdc.wchar_ : wcslen; import core.stdc.wchar_ : wcslen;
import std.conv : to; import std.conv : to;
auto len = wcslen(namez); auto len = namez ? wcslen(namez) : 0;
name = to!string(namez[0 .. len]); name = to!string(namez[0 .. len]);
} }
throw new FileException(name, .GetLastError(), file, line); throw new FileException(name, .GetLastError(), file, line);
@ -197,12 +197,23 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
{ {
import core.stdc.string : strlen; import core.stdc.string : strlen;
auto len = strlen(namez); auto len = namez ? strlen(namez) : 0;
name = namez[0 .. len].idup; name = namez[0 .. len].idup;
} }
throw new FileException(name, .errno, file, line); throw new FileException(name, .errno, file, line);
} }
unittest
{
// issue 17102
try
{
cenforce(false, null, null,
__FILE__, __LINE__);
}
catch (FileException) {}
}
/* ********************************** /* **********************************
* Basic File operations. * Basic File operations.
*/ */