Skip to content

Commit

Permalink
Merge pull request #87 from awnumar/pages
Browse files Browse the repository at this point in the history
canary: remove lower bound limit on length
  • Loading branch information
awnumar authored Jun 17, 2019
2 parents 7df3159 + a2fa811 commit 4b075c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewBuffer(size int) (*Buffer, error) {
b := new(Buffer)

// Allocate the total needed memory
innerLen := roundToPageSize(size + 32)
innerLen := roundToPageSize(size)
b.memory, err = memcall.Alloc((2 * pageSize) + innerLen)
if err != nil {
Panic(err)
Expand All @@ -68,7 +68,7 @@ func NewBuffer(size int) (*Buffer, error) {
b.postguard = getBytes(&b.memory[pageSize+innerLen], pageSize)

// Construct slice reference for canary portion of inner page.
b.canary = getBytes(&b.memory[pageSize], len(b.inner)-len(b.data)-32)
b.canary = getBytes(&b.memory[pageSize], len(b.inner)-len(b.data))

// Lock the pages that will hold sensitive data.
if err := memcall.Lock(b.inner); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func TestLotsOfAllocs(t *testing.T) {
if len(b.data) != i {
t.Error("invalid data length")
}
if len(b.memory) != roundToPageSize(i+32)+2*pageSize {
if len(b.memory) != roundToPageSize(i)+2*pageSize {
t.Error("memory length invalid")
}
if len(b.preguard) != pageSize || len(b.postguard) != pageSize {
t.Error("guard pages length invalid")
}
if len(b.canary) != len(b.inner)-i-32 {
if len(b.canary) != len(b.inner)-i {
t.Error("canary length invalid")
}
b.Destroy()
Expand Down

0 comments on commit 4b075c2

Please sign in to comment.