]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
check for invalid utf-8, and toss it back to avoid crashes
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Nov 2008 22:39:42 +0000 (17:39 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Nov 2008 22:39:42 +0000 (17:39 -0500)
Since ikiwiki uses open :utf8, perl assumes that files contain valid utf-8.
If it turns out to be malformed it may later crash while processing strings
read from them, with 'Malformed UTF-8 character (fatal)'.

As at least a quick fix, use utf8::valid as soon as data is read, and if
it's not valid, call encode_utf8 on the string, thus clearing the utf-8
flag. This may cause follow-on encoding problems, but will avoid this
crash, and the input file was broken anyway, so GIGO is a reasonable
response. (I looked at calling decode_utf8 after, but it seemed to cause
more trouble than it was worth. BTW, use open ':encoding(utf8)' avaoids
this problem, but the corrupted data later causes Storable to crash when
writing the index.)

This is a quick fix, clearly imperfect:
- It might be better to explicitly call decode_utf8 when reading files,
  rather than using the IO layer.
- Data read other than by readfile() can still sneak in bad utf-8. While
  ikiwiki does very little file input not using it, stdin for the CGI
  would be one way.
(cherry picked from commit 716560b7f15b6e15b246c39c11eb8181d91c8662)

Conflicts:

debian/changelog

IkiWiki.pm
debian/changelog
doc/security.mdwn

index d2f7dcc06b7eb4ef3579e33bbefb82cfdfacaa1a..443c7044796a29947936fd5de57e8e09c14bfec4 100644 (file)
@@ -334,6 +334,10 @@ sub readfile ($;$$) { #{{{
        binmode($in) if ($binary);
        return \*$in if $wantfd;
        my $ret=<$in>;
+       # check for invalid utf-8, and toss it back to avoid crashes
+       if (! utf8::valid($ret)) {
+               $ret=encode_utf8($ret);
+       }
        close $in || error("failed to read $file: $!");
        return $ret;
 } #}}}
index cb9bc4a73646d3ef1d710d31e601b896f2977056..a0e1efceacaa981f0db87e7b1659e35071f1c633 100644 (file)
@@ -1,5 +1,6 @@
 ikiwiki (2.53.3) UNRELEASED; urgency=low
 
+  * Avoid crash on malformed utf-8 discovered by intrigeri.
   * orphans: Fix unquoted page name in regexp.
 
  -- Joey Hess <joeyh@debian.org>  Thu, 09 Oct 2008 19:12:18 -0400
index 52ef486e69f425751296a510f4350e8c33ab9051..403de81de8750ee0c465f674ecaac8343b206a8c 100644 (file)
@@ -408,3 +408,12 @@ discovered on 30 May 2008 and fixed the same day. ([[cve CVE-2008-0169]])
 
 I recommend upgrading to 2.48 immediatly if your wiki allows both password
 and openid logins.
+
+## Malformed UTF-8 DOS
+
+Feeding ikiwiki page sources containing certian forms of malformed UTF-8
+can cause it to crash. This can potentially be used for a denial of service
+attack.
+
+intrigeri discovered this problem on 12 Nov 2008 and a patch put in place
+later that day.