shithub: mc

Download patch

ref: aa4849acf33141833a8383548ac367d6d072e129
parent: 677eeb4ac8e7d1e7577e509da0ab481b10f327a9
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]
 }