about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-28 22:03:58 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-28 22:03:58 -0700
commitdcb6a21a911d61c51d1f54c357b5c6fcb01dd7cc (patch)
tree91be83a868bd8e04f3eba2b4ec7889b1b72f5cb4 /shell
parent7fa356abef56cc72e730f7bc0648c3968a3464d6 (diff)
downloadmu-dcb6a21a911d61c51d1f54c357b5c6fcb01dd7cc.tar.gz
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.
Diffstat (limited to 'shell')
-rw-r--r--shell/global.mu5
-rw-r--r--shell/sandbox.mu2
2 files changed, 5 insertions, 2 deletions
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)