ref: 75f404b16e4bde907d084bbe637c2b96f9d02c67
parent: 1b92befa76f09641c30fa751ce33af5ab47c4499
author: Ori Bernstein <[email protected]>
date: Sun Sep 14 18:43:45 EDT 2014
Fix 'strstrip()' out of bounds access. Our first character check was out of bounds.
--- a/libstd/strstrip.myr
+++ b/libstd/strstrip.myr
@@ -1,6 +1,7 @@
use "types.use"
use "utf.use"
use "chartype.use"
+use "fmt.use"
pkg std =
const strstrip : (str : byte[:] -> byte[:])
@@ -32,13 +33,12 @@
/* scan backwards for start of utf8 char */
end = str.len
for i = str.len; i != 0; i--
- if str[i] & 0x80 == 0
+ if str[i - 1] & 0x80 == 0 || str[i-1] & 0xc0 != 0x80
if !isspace(decode(str[i-1:]))
- goto donestrip
+ break
;;
end = i - 1
;;
;;
-:donestrip
-> str[:end]
}