From e74050ade4ae37f5e2cb2fc09af405dd5f03cd2c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 7 May 2021 18:25:43 -0700 Subject: always check for null in 'get' instructions --- linux/313index-bounds-check.subx | 8 +++++++ linux/mu | Bin 603681 -> 604512 bytes linux/mu.subx | 48 ++++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 13 deletions(-) (limited to 'linux') diff --git a/linux/313index-bounds-check.subx b/linux/313index-bounds-check.subx index 615935b3..1d7384c1 100644 --- a/linux/313index-bounds-check.subx +++ b/linux/313index-bounds-check.subx @@ -84,3 +84,11 @@ __check-mu-array-bounds:overflow: # "81 0/subop/add %esp 4/imm32" # drop function name # # actually save the index addr in reg # "8d/copy-address *(" rega "+" regi "<<" log2(size-of(T)) "+4) " reg "/r32" + +__mu-abort-null-get-base-address: + (write-buffered Stderr "null address in 'get'\n") + (flush Stderr) + # exit(1) + bb/copy-to-ebx 1/imm32 + e8/call syscall_exit/disp32 + # never gets here diff --git a/linux/mu b/linux/mu index a8d00898..2b2b8476 100755 Binary files a/linux/mu and b/linux/mu differ diff --git a/linux/mu.subx b/linux/mu.subx index 2326f4b1..4ccf4854 100644 --- a/linux/mu.subx +++ b/linux/mu.subx @@ -6879,16 +6879,20 @@ test-convert-function-and-type-definition: (check-next-stream-line-equal _test-output-stream " ff 6/subop/push %eax" "F - test-convert-function-and-type-definition/6") (check-next-stream-line-equal _test-output-stream " 8b/-> *(ebp+0x00000008) 0x00000000/r32" "F - test-convert-function-and-type-definition/7") (check-next-stream-line-equal _test-output-stream " ff 6/subop/push %ecx" "F - test-convert-function-and-type-definition/8") - (check-next-stream-line-equal _test-output-stream " 8d/copy-address *(eax + 0x00000000) 0x00000001/r32" "F - test-convert-function-and-type-definition/9") - (check-next-stream-line-equal _test-output-stream " 8d/copy-address *(eax + 0x00000004) 0x00000001/r32" "F - test-convert-function-and-type-definition/11") - (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %ecx" "F - test-convert-function-and-type-definition/13") - (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %eax" "F - test-convert-function-and-type-definition/14") - (check-next-stream-line-equal _test-output-stream " }" "F - test-convert-function-and-type-definition/15") - (check-next-stream-line-equal _test-output-stream "$foo:0x00000001:break:" "F - test-convert-function-and-type-definition/16") - (check-next-stream-line-equal _test-output-stream " # . epilogue" "F - test-convert-function-and-type-definition/17") - (check-next-stream-line-equal _test-output-stream " 89/<- %esp 5/r32/ebp" "F - test-convert-function-and-type-definition/18") - (check-next-stream-line-equal _test-output-stream " 5d/pop-to-ebp" "F - test-convert-function-and-type-definition/19") - (check-next-stream-line-equal _test-output-stream " c3/return" "F - test-convert-function-and-type-definition/20") + (check-next-stream-line-equal _test-output-stream " 81 7/subop/compare %eax 0/imm32" "F - test-convert-function-and-type-definition/9") + (check-next-stream-line-equal _test-output-stream " 0f 84/jump-if-= __mu-abort-null-get-base-address/disp32" "F - test-convert-function-and-type-definition/10") + (check-next-stream-line-equal _test-output-stream " 8d/copy-address *(eax + 0x00000000) 0x00000001/r32" "F - test-convert-function-and-type-definition/11") + (check-next-stream-line-equal _test-output-stream " 81 7/subop/compare %eax 0/imm32" "F - test-convert-function-and-type-definition/12") + (check-next-stream-line-equal _test-output-stream " 0f 84/jump-if-= __mu-abort-null-get-base-address/disp32" "F - test-convert-function-and-type-definition/13") + (check-next-stream-line-equal _test-output-stream " 8d/copy-address *(eax + 0x00000004) 0x00000001/r32" "F - test-convert-function-and-type-definition/14") + (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %ecx" "F - test-convert-function-and-type-definition/15") + (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %eax" "F - test-convert-function-and-type-definition/16") + (check-next-stream-line-equal _test-output-stream " }" "F - test-convert-function-and-type-definition/17") + (check-next-stream-line-equal _test-output-stream "$foo:0x00000001:break:" "F - test-convert-function-and-type-definition/18") + (check-next-stream-line-equal _test-output-stream " # . epilogue" "F - test-convert-function-and-type-definition/19") + (check-next-stream-line-equal _test-output-stream " 89/<- %esp 5/r32/ebp" "F - test-convert-function-and-type-definition/20") + (check-next-stream-line-equal _test-output-stream " 5d/pop-to-ebp" "F - test-convert-function-and-type-definition/21") + (check-next-stream-line-equal _test-output-stream " c3/return" "F - test-convert-function-and-type-definition/22") # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp @@ -29754,17 +29758,35 @@ translate-mu-get-stmt: # out: (addr buffered-file), stmt: (addr stmt) 50/push-eax 51/push-ecx 52/push-edx - # - (emit-indent *(ebp+8) *Curr-block-depth) - (write-buffered *(ebp+8) "8d/copy-address ") # ecx = stmt 8b/-> *(ebp+0xc) 1/r32/ecx + # var base/eax: (addr var) = stmt->inouts->value + (lookup *(ecx+0xc) *(ecx+0x10)) # Stmt1-inouts Stmt1-inouts => eax + (lookup *eax *(eax+4)) # Stmt-var-value Stmt-var-value => eax + # if base is in a register, insert a null check + 81 7/subop/compare *(eax+0x18) 0/imm32 # Var-register + { + 0f 84/jump-if-= break/disp32 +$translate-mu-get-stmt:emit-null-check-for-register-input: + # emit "81 7/subop/compare %" base->register " 0/imm32\n" + (emit-indent *(ebp+8) *Curr-block-depth) + (write-buffered *(ebp+8) "81 7/subop/compare %") + (lookup *(eax+0x18) *(eax+0x1c)) # Var-register Var-register => eax + (write-buffered *(ebp+8) %eax) + (write-buffered *(ebp+8) " 0/imm32\n") + # + (emit-indent *(ebp+8) *Curr-block-depth) + (write-buffered *(ebp+8) "0f 84/jump-if-= __mu-abort-null-get-base-address/disp32\n") + } # var offset/edx: int = get offset of stmt (mu-get-offset %ecx) # => eax 89/<- %edx 0/r32/eax # var base/eax: (addr var) = stmt->inouts->value (lookup *(ecx+0xc) *(ecx+0x10)) # Stmt1-inouts Stmt1-inouts => eax (lookup *eax *(eax+4)) # Stmt-var-value Stmt-var-value => eax + # + (emit-indent *(ebp+8) *Curr-block-depth) + (write-buffered *(ebp+8) "8d/copy-address ") # if base is in a register 81 7/subop/compare *(eax+0x18) 0/imm32 # Var-register { -- cgit 1.4.1-2-gfad0 23' href='#n123'>123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213