Skip to content

Commit

Permalink
Merge pull request #2459 from denis-sh/fix-temp-c-string-allocation
Browse files Browse the repository at this point in the history
Fix Issue 13367 - Buffer overflow when setting PATH
  • Loading branch information
DmitryOlshansky committed Aug 25, 2014
2 parents 5fb71bb + 46d0e01 commit 2d7bcea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion std/internal/cstring.d
Expand Up @@ -161,6 +161,14 @@ nothrow @nogc unittest
assert("abc".tempCString!wchar().buffPtr.asArray == "abc"w);
}

// Test for Issue 13367: ensure there is no memory corruption
nothrow @nogc unittest
{
@property str(C)() { C[300] arr = 'a'; return arr; }
assert(str!char.tempCString!wchar().asArray == str!wchar);
assert(str!char.tempCString!dchar().asArray == str!dchar);
}

version(Windows)
alias tempCStringW = tempCString!(wchar, char);

Expand Down Expand Up @@ -294,7 +302,7 @@ body
if(overflow)
onOutOfMemoryError();

auto ptr = cast(T*) tryRawAllocate(count);
auto ptr = cast(T*) tryRawAllocate(buffBytes);
if(!ptr)
onOutOfMemoryError();

Expand Down

0 comments on commit 2d7bcea

Please sign in to comment.