forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`func uiEvt(e termbox.Event) Event` used to change the type of termbox.Event to Event by using some pointer-cast magic[1], which could cause an overflow if `termbox.Event` changes its structure. I'd rather just have `type Event termbox.Event` but that would break backwards compatibility. Warning: A buffer overflow could cause a serious security issue but it is very unlikely that anyone could exploit that (though not impossbible). You'd need to push a upstream update to termbox, which would tweak termbox.Event's structure. Still, this issue should be fixed and unsafe should never be used. [1] it used to get the address of termbox.Event and just cast a Event pointer
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2015 Zack Guo <[email protected]>. All rights reserved. | ||
// Use of this source code is governed by a MIT license that can | ||
// be found in the LICENSE file. | ||
// | ||
// Portions of this file uses [termbox-go](https://github.com/nsf/termbox-go/blob/54b74d087b7c397c402d0e3b66d2ccb6eaf5c2b4/api_common.go) | ||
// by [authors](https://github.com/nsf/termbox-go/blob/master/AUTHORS) | ||
// under [license](https://github.com/nsf/termbox-go/blob/master/LICENSE) | ||
|
||
package termui | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
termbox "github.com/nsf/termbox-go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type boxEvent termbox.Event | ||
|
||
func TestUiEvt(t *testing.T) { | ||
err := errors.New("This is a mock error") | ||
event := boxEvent{3, 5, 2, 'H', 200, 500, err, 50, 30, 2} | ||
expetced := Event{3, 5, 2, 'H', 200, 500, err, 50, 30, 2} | ||
|
||
// We need to do that ugly casting so that vet does not complain | ||
assert.Equal(t, uiEvt(termbox.Event(event)), expetced) | ||
} |