pidgin: 635702e2: Add a silly little check to make sure ou...

markdoliner at pidgin.im markdoliner at pidgin.im
Wed Jun 22 13:45:57 EDT 2011


----------------------------------------------------------------------
Revision: 635702e269dd4913ebb13f96b885d4eeb7c874d7
Parent:   6cf1aee8ac5e3c836af832eaf26ccedd611dc70b
Author:   markdoliner at pidgin.im
Date:     06/22/11 13:43:51
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/635702e269dd4913ebb13f96b885d4eeb7c874d7

Changelog: 

Add a silly little check to make sure our xml parser isn't vulnerable to the
billion laughs attack.  I think because we specify NULL as the entity
resolver, attempts to define entities in an xml doc just get ignored.

Changes against parent 6cf1aee8ac5e3c836af832eaf26ccedd611dc70b

  added    libpurple/tests/test_xmlnode.c
  patched  libpurple/tests/Makefile.am
  patched  libpurple/tests/check_libpurple.c
  patched  libpurple/tests/tests.h

-------------- next part --------------
============================================================
--- libpurple/tests/Makefile.am	256ff6715c0747d546cea255e3cca40ddc5511e5
+++ libpurple/tests/Makefile.am	1b32d76405de31876764ab0f079cd2fd334b6d5f
@@ -17,6 +17,7 @@ check_libpurple_SOURCES=\
 		test_oscar_util.c \
 		test_yahoo_util.c \
 		test_util.c \
+		test_xmlnode.c \
 		$(top_builddir)/libpurple/util.h
 
 check_libpurple_CFLAGS=\
============================================================
--- libpurple/tests/check_libpurple.c	8a62e5a281d8c0eeff425de91984e7b01fe96f64
+++ libpurple/tests/check_libpurple.c	21c3223b688da66641277b5fb49c9e08f5ca3f92
@@ -91,6 +91,7 @@ int main(void)
 	srunner_add_suite(sr, oscar_util_suite());
 	srunner_add_suite(sr, yahoo_util_suite());
 	srunner_add_suite(sr, util_suite());
+	srunner_add_suite(sr, xmlnode_suite());
 
 	/* make this a libpurple "ui" */
 	purple_check_init();
============================================================
--- libpurple/tests/tests.h	03054dc9017d4c0af1862ae41859da59cb11229e
+++ libpurple/tests/tests.h	60a4d73ccdf2e1faf83df3e76036493ee2868f66
@@ -16,6 +16,7 @@ Suite * util_suite(void);
 Suite * oscar_util_suite(void);
 Suite * yahoo_util_suite(void);
 Suite * util_suite(void);
+Suite * xmlnode_suite(void);
 
 /* helper macros */
 #define assert_int_equal(expected, actual) { \
============================================================
--- /dev/null	
+++ libpurple/tests/test_xmlnode.c	ef8840551902714078a88e375c19a8caf02be7d8
@@ -0,0 +1,34 @@
+#include <string.h>
+
+#include "tests.h"
+#include "../xmlnode.h"
+
+/*
+ * If we really wanted to test the billion laughs attack we would
+ * need to have more than just 4 ha's.  But as long as this shorter
+ * document fails to parse, the longer one should also fail to parse.
+ */
+START_TEST(test_xmlnode_billion_laughs_attack)
+{
+	const char *malicious_xml_doc = "<!DOCTYPE root [ <!ENTITY ha \"Ha !\"><!ENTITY ha2 \"&ha; &ha;\"><!ENTITY ha3 \"&ha2; &ha2;\"> ]><root>&ha3;</root>";
+
+	/* Uncomment this line if you want to see the error message given by
+	   the parser for the above XML document */
+	/* purple_debug_set_enabled(TRUE); */
+
+	fail_if(xmlnode_from_str(malicious_xml_doc, -1),
+			"xmlnode_from_str() returned an XML tree, but we didn't want it to");
+}
+END_TEST
+
+Suite *
+xmlnode_suite(void)
+{
+	Suite *s = suite_create("Utility Functions");
+
+	TCase *tc = tcase_create("xmlnode");
+	tcase_add_test(tc, test_xmlnode_billion_laughs_attack);
+	suite_add_tcase(s, tc);
+
+	return s;
+}


More information about the Commits mailing list