Skip to content

Commit

Permalink
Fix buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRiDDeR committed Oct 16, 2023
1 parent 294ac9e commit a279b09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 DarkRIDDeR
Copyright (c) 2019-23 DarkRiDDeR, n8sh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion dub.sdl
@@ -1,6 +1,6 @@
name "zero-memory"
description "This is a function implementation SecureZeroMemory in D programming language"
license "DarkRiDDeR"
copyright "Copyright © 2019, DarkRiDDeR"
copyright "Copyright (c) 2019-23 DarkRiDDeR, n8sh"
license "MIT License"
targetType "library"
18 changes: 15 additions & 3 deletions src/zero_memory/package.d
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2019 DarkRiDDeR
Copyright (c) 2019-23 DarkRiDDeR, n8sh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -45,7 +45,7 @@ pure nothrow @nogc
mov RCX, length;
iter:
xor RBX, RBX;
mov [RDX], RBX;
mov [RDX], BL;
inc RDX;
loop iter;
}
Expand All @@ -60,7 +60,7 @@ pure nothrow @nogc
mov ECX, length;
iter:
xor EBX, EBX;
mov [EDX], EBX;
mov [EDX], BL;
inc EDX;
loop iter;
}
Expand Down Expand Up @@ -126,4 +126,16 @@ unittest
i2 = [8, 5, 99, 5, 99];
secureZeroMemory(cast(void[])i2);
assert(i == i2);

// Verify that secureZeroMemory doesn't have a buffer overrun.
ubyte[17] array;
array[] = 1;
ubyte[] slice = array[1..$-1];
secureZeroMemory(slice);
// Slice should be 0.
foreach (b; slice)
assert(b == 0);
// Bytes outside slice should be 1.
assert(array[0] == 1);
assert(array[$-1] == 1);
}

1 comment on commit a279b09

@DarkRiDDeR
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.