Skip to content

Commit

Permalink
Merge pull request #5049 from Burgos/fix-17102
Browse files Browse the repository at this point in the history
fix issue 17102 - Don't pass null to strlen in std.file.cenforce
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
  • Loading branch information
dlang-bot authored Jan 21, 2017
2 parents 366f6e4 + e80d3b5 commit c6d3350
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
import core.stdc.wchar_ : wcslen;
import std.conv : to;

auto len = wcslen(namez);
auto len = namez ? wcslen(namez) : 0;
name = to!string(namez[0 .. len]);
}
throw new FileException(name, .GetLastError(), file, line);
Expand All @@ -197,12 +197,23 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
{
import core.stdc.string : strlen;

auto len = strlen(namez);
auto len = namez ? strlen(namez) : 0;
name = namez[0 .. len].idup;
}
throw new FileException(name, .errno, file, line);
}

unittest
{
// issue 17102
try
{
cenforce(false, null, null,
__FILE__, __LINE__);
}
catch (FileException) {}
}

/* **********************************
* Basic File operations.
*/
Expand Down

0 comments on commit c6d3350

Please sign in to comment.