From dcb6a21a911d61c51d1f54c357b5c6fcb01dd7cc Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 28 Apr 2021 22:03:58 -0700 Subject: bugfix: initialize gap buffers before using them I keep running into one hole in Mu's memory-safety since dropping the Linux dependency: null pointers no longer error when dereferenced. Here the problem manifests as aliasing: lots of gap buffers share the same exact data near address 0, because it was never initialized. --- shell/global.mu | 5 ++++- shell/sandbox.mu | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/global.mu b/shell/global.mu index 52b68f80..c5b11471 100644 --- a/shell/global.mu +++ b/shell/global.mu @@ -76,8 +76,9 @@ fn load-globals in: (addr handle cell), self: (addr global-table) { var value-gap-buffer-ah/edx: (addr handle gap-buffer) <- address value-gap-buffer-storage allocate value-gap-buffer-ah var value-gap-buffer/eax: (addr gap-buffer) <- lookup *value-gap-buffer-ah + initialize-gap-buffer value-gap-buffer, 0x1000/4KB load-gap-buffer-from-stream value-gap-buffer, value-data - read-evaluate-and-stash-to-globals value-gap-buffer-ah, self + read-evaluate-and-move-to-globals value-gap-buffer-ah, self loop } } @@ -154,6 +155,8 @@ fn render-globals screen: (addr screen), _self: (addr global-table), xmin: int, var curr-input-ah/edx: (addr handle gap-buffer) <- get curr, input var _curr-input/eax: (addr gap-buffer) <- lookup *curr-input-ah var curr-input/ebx: (addr gap-buffer) <- copy _curr-input + compare curr-input, 0 + break-if-= var x/eax: int <- copy xmin x, y <- render-gap-buffer-wrapping-right-then-down screen, curr-input, xmin, y, xmax, ymax, 0/no-cursor } diff --git a/shell/sandbox.mu b/shell/sandbox.mu index 11d109b8..0bc856bf 100644 --- a/shell/sandbox.mu +++ b/shell/sandbox.mu @@ -730,7 +730,7 @@ fn run _in-ah: (addr handle gap-buffer), out: (addr stream byte), globals: (addr mark-lines-dirty trace } -fn read-evaluate-and-stash-to-globals _in-ah: (addr handle gap-buffer), globals: (addr global-table) { +fn read-evaluate-and-move-to-globals _in-ah: (addr handle gap-buffer), globals: (addr global-table) { var in-ah/eax: (addr handle gap-buffer) <- copy _in-ah var in/eax: (addr gap-buffer) <- lookup *in-ah var read-result-h: (handle cell) -- cgit 1.4.1-2-gfad0