nokogiri-xmlsec1 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +13 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +133 -0
  9. data/Rakefile +30 -0
  10. data/dependencies.yml +3 -0
  11. data/ext/nokogiri_ext_xmlsec/extconf.rb +489 -0
  12. data/ext/nokogiri_ext_xmlsec/init.c +46 -0
  13. data/ext/nokogiri_ext_xmlsec/nokogiri_decrypt_with_key.c +124 -0
  14. data/ext/nokogiri_ext_xmlsec/nokogiri_encrypt_with_key.c +182 -0
  15. data/ext/nokogiri_ext_xmlsec/nokogiri_helpers_set_attribute_id.c +43 -0
  16. data/ext/nokogiri_ext_xmlsec/nokogiri_init.c +32 -0
  17. data/ext/nokogiri_ext_xmlsec/nokogiri_sign_certificate.c +104 -0
  18. data/ext/nokogiri_ext_xmlsec/nokogiri_sign_rsa.c +95 -0
  19. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_certificates.c +96 -0
  20. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_named_keys.c +106 -0
  21. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_rsa.c +56 -0
  22. data/ext/nokogiri_ext_xmlsec/shutdown.c +12 -0
  23. data/ext/nokogiri_ext_xmlsec/xmlsecrb.h +39 -0
  24. data/lib/nokogiri-xmlsec.rb +1 -0
  25. data/lib/xmlsec.rb +110 -0
  26. data/lib/xmlsec/version.rb +3 -0
  27. data/nokogiri-xmlsec1.gemspec +46 -0
  28. data/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch +265 -0
  29. data/ports/patches/libxml2/0002-Fix-entities-local-buffers-size-problems.patch +102 -0
  30. data/ports/patches/libxml2/0003-Fix-an-error-in-previous-commit.patch +26 -0
  31. data/ports/patches/libxml2/0004-Fix-potential-out-of-bound-access.patch +26 -0
  32. data/ports/patches/libxml2/0005-Detect-excessive-entities-expansion-upon-replacement.patch +158 -0
  33. data/ports/patches/libxml2/0006-Do-not-fetch-external-parsed-entities.patch +78 -0
  34. data/ports/patches/libxml2/0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch +480 -0
  35. data/ports/patches/libxml2/0008-Improve-handling-of-xmlStopParser.patch +315 -0
  36. data/ports/patches/libxml2/0009-Fix-a-couple-of-return-without-value.patch +37 -0
  37. data/ports/patches/libxml2/0010-Keep-non-significant-blanks-node-in-HTML-parser.patch +2006 -0
  38. data/ports/patches/libxml2/0011-Do-not-fetch-external-parameter-entities.patch +39 -0
  39. data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +222 -0
  40. data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +53 -0
  41. data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +60 -0
  42. data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +42 -0
  43. data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +164 -0
  44. data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +587 -0
  45. data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +80 -0
  46. data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +185 -0
  47. data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +126 -0
  48. data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +25 -0
  49. data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +43 -0
  50. data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +41 -0
  51. data/ports/patches/xmlsec1/.keep +0 -0
  52. data/spec/fixtures/cert/server.crt +14 -0
  53. data/spec/fixtures/cert/server.csr +11 -0
  54. data/spec/fixtures/cert/server.key.decrypted +15 -0
  55. data/spec/fixtures/cert/server.key.encrypted +18 -0
  56. data/spec/fixtures/rsa.pem +15 -0
  57. data/spec/fixtures/rsa.pub +6 -0
  58. data/spec/fixtures/sign2-doc.xml +6 -0
  59. data/spec/fixtures/sign2-result.xml +24 -0
  60. data/spec/fixtures/sign3-result.xml +37 -0
  61. data/spec/lib/nokogiri/xml/document/encryption_and_decryption_spec.rb +22 -0
  62. data/spec/lib/nokogiri/xml/document/signing_and_verifying_spec.rb +77 -0
  63. data/spec/spec_helper.rb +10 -0
  64. metadata +251 -0
@@ -0,0 +1,3 @@
1
+ module Xmlsec
2
+ VERSION = '0.0.6'
3
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'xmlsec/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'nokogiri-xmlsec1'
9
+ spec.version = Xmlsec::VERSION
10
+ spec.summary = %q{Wrapper around http://www.aleksey.com/xmlsec to
11
+ support XML encryption, decryption, signing and signature validation in
12
+ Ruby}
13
+ spec.description = %q{This is a fork of nokogiri-xmlsec.
14
+ This fork uses mini_portile to improve code predictiveness and allow heroku deploys.
15
+ This gem adds support to Ruby for encrypting, decrypting, signing and validating
16
+ the signatures of XML documents, according to the [XML Encryption Syntax and
17
+ Processing](http://www.w3.org/TR/xmlenc-core/) standard, by wrapping around the
18
+ [xmlsec1](http://www.aleksey.com/xmlsec) C library and adding relevant methods
19
+ to `Nokogiri::XML::Document`.}
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.license = 'MIT'
24
+
25
+ spec.author = 'Renan Mendes Carvalho'
26
+ spec.email = ['aitherios@gmail.com']
27
+ spec.homepage = 'https://github.com/aitherios/nokogiri-xmlsec1'
28
+
29
+ spec.files = `git ls-files`.split($/)
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
32
+ spec.require_paths = ['lib']
33
+ spec.extensions = %w{ext/nokogiri_ext_xmlsec/extconf.rb}
34
+
35
+ spec.add_dependency 'nokogiri', '>= 0'
36
+ spec.add_dependency 'mini_portile', '0.6.0'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.3'
39
+ spec.add_development_dependency 'rake', '>= 0'
40
+ spec.add_development_dependency 'rake-compiler', '>= 0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'guard-rspec', '>= 0'
43
+ spec.add_development_dependency 'guard-rake', '>= 0'
44
+ spec.add_development_dependency 'wwtd', '>= 0'
45
+
46
+ end
@@ -0,0 +1,265 @@
1
+ From bc168aab5749acbe6630a29be4dcfabf0a81e2da Mon Sep 17 00:00:00 2001
2
+ From: Daniel Veillard <veillard@redhat.com>
3
+ Date: Tue, 17 Jul 2012 16:19:17 +0800
4
+ Subject: [PATCH 1/9] Fix parser local buffers size problems
5
+
6
+ [Origin: 459eeb9dc752d5185f57ff6b135027f11981a626]
7
+ ---
8
+ parser.c | 74 +++++++++++++++++++++++++++++++++++++---------------------------
9
+ 1 file changed, 43 insertions(+), 31 deletions(-)
10
+
11
+ diff --git a/parser.c b/parser.c
12
+ index 2c38fae..9863275 100644
13
+ --- a/parser.c
14
+ +++ b/parser.c
15
+ @@ -40,6 +40,7 @@
16
+ #endif
17
+
18
+ #include <stdlib.h>
19
+ +#include <limits.h>
20
+ #include <string.h>
21
+ #include <stdarg.h>
22
+ #include <libxml/xmlmemory.h>
23
+ @@ -117,10 +118,10 @@ xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID,
24
+ * parser option.
25
+ */
26
+ static int
27
+ -xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned long size,
28
+ +xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
29
+ xmlEntityPtr ent)
30
+ {
31
+ - unsigned long consumed = 0;
32
+ + size_t consumed = 0;
33
+
34
+ if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
35
+ return (0);
36
+ @@ -2589,15 +2590,17 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
37
+
38
+ /*
39
+ * Macro used to grow the current buffer.
40
+ + * buffer##_size is expected to be a size_t
41
+ + * mem_error: is expected to handle memory allocation failures
42
+ */
43
+ #define growBuffer(buffer, n) { \
44
+ xmlChar *tmp; \
45
+ - buffer##_size *= 2; \
46
+ - buffer##_size += n; \
47
+ - tmp = (xmlChar *) \
48
+ - xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
49
+ + size_t new_size = buffer##_size * 2 + n; \
50
+ + if (new_size < buffer##_size) goto mem_error; \
51
+ + tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
52
+ if (tmp == NULL) goto mem_error; \
53
+ buffer = tmp; \
54
+ + buffer##_size = new_size; \
55
+ }
56
+
57
+ /**
58
+ @@ -2623,14 +2626,14 @@ xmlChar *
59
+ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
60
+ int what, xmlChar end, xmlChar end2, xmlChar end3) {
61
+ xmlChar *buffer = NULL;
62
+ - int buffer_size = 0;
63
+ + size_t buffer_size = 0;
64
+ + size_t nbchars = 0;
65
+
66
+ xmlChar *current = NULL;
67
+ xmlChar *rep = NULL;
68
+ const xmlChar *last;
69
+ xmlEntityPtr ent;
70
+ int c,l;
71
+ - int nbchars = 0;
72
+
73
+ if ((ctxt == NULL) || (str == NULL) || (len < 0))
74
+ return(NULL);
75
+ @@ -2647,7 +2650,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
76
+ * allocate a translation buffer.
77
+ */
78
+ buffer_size = XML_PARSER_BIG_BUFFER_SIZE;
79
+ - buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar));
80
+ + buffer = (xmlChar *) xmlMallocAtomic(buffer_size);
81
+ if (buffer == NULL) goto mem_error;
82
+
83
+ /*
84
+ @@ -2667,7 +2670,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
85
+ if (val != 0) {
86
+ COPY_BUF(0,buffer,nbchars,val);
87
+ }
88
+ - if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
89
+ + if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
90
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
91
+ }
92
+ } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {
93
+ @@ -2685,7 +2688,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
94
+ (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
95
+ if (ent->content != NULL) {
96
+ COPY_BUF(0,buffer,nbchars,ent->content[0]);
97
+ - if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
98
+ + if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
99
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
100
+ }
101
+ } else {
102
+ @@ -2702,8 +2705,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
103
+ current = rep;
104
+ while (*current != 0) { /* non input consuming loop */
105
+ buffer[nbchars++] = *current++;
106
+ - if (nbchars >
107
+ - buffer_size - XML_PARSER_BUFFER_SIZE) {
108
+ + if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
109
+ if (xmlParserEntityCheck(ctxt, nbchars, ent))
110
+ goto int_error;
111
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
112
+ @@ -2717,7 +2719,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
113
+ const xmlChar *cur = ent->name;
114
+
115
+ buffer[nbchars++] = '&';
116
+ - if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) {
117
+ + if (nbchars + i + XML_PARSER_BUFFER_SIZE > buffer_size) {
118
+ growBuffer(buffer, i + XML_PARSER_BUFFER_SIZE);
119
+ }
120
+ for (;i > 0;i--)
121
+ @@ -2745,8 +2747,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
122
+ current = rep;
123
+ while (*current != 0) { /* non input consuming loop */
124
+ buffer[nbchars++] = *current++;
125
+ - if (nbchars >
126
+ - buffer_size - XML_PARSER_BUFFER_SIZE) {
127
+ + if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
128
+ if (xmlParserEntityCheck(ctxt, nbchars, ent))
129
+ goto int_error;
130
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
131
+ @@ -2759,8 +2760,8 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
132
+ } else {
133
+ COPY_BUF(l,buffer,nbchars,c);
134
+ str += l;
135
+ - if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
136
+ - growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
137
+ + if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
138
+ + growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
139
+ }
140
+ }
141
+ if (str < last)
142
+ @@ -3764,8 +3765,8 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
143
+ xmlChar limit = 0;
144
+ xmlChar *buf = NULL;
145
+ xmlChar *rep = NULL;
146
+ - int len = 0;
147
+ - int buf_size = 0;
148
+ + size_t len = 0;
149
+ + size_t buf_size = 0;
150
+ int c, l, in_space = 0;
151
+ xmlChar *current = NULL;
152
+ xmlEntityPtr ent;
153
+ @@ -3787,7 +3788,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
154
+ * allocate a translation buffer.
155
+ */
156
+ buf_size = XML_PARSER_BUFFER_SIZE;
157
+ - buf = (xmlChar *) xmlMallocAtomic(buf_size * sizeof(xmlChar));
158
+ + buf = (xmlChar *) xmlMallocAtomic(buf_size);
159
+ if (buf == NULL) goto mem_error;
160
+
161
+ /*
162
+ @@ -3804,7 +3805,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
163
+
164
+ if (val == '&') {
165
+ if (ctxt->replaceEntities) {
166
+ - if (len > buf_size - 10) {
167
+ + if (len + 10 > buf_size) {
168
+ growBuffer(buf, 10);
169
+ }
170
+ buf[len++] = '&';
171
+ @@ -3813,7 +3814,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
172
+ * The reparsing will be done in xmlStringGetNodeList()
173
+ * called by the attribute() function in SAX.c
174
+ */
175
+ - if (len > buf_size - 10) {
176
+ + if (len + 10 > buf_size) {
177
+ growBuffer(buf, 10);
178
+ }
179
+ buf[len++] = '&';
180
+ @@ -3823,7 +3824,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
181
+ buf[len++] = ';';
182
+ }
183
+ } else if (val != 0) {
184
+ - if (len > buf_size - 10) {
185
+ + if (len + 10 > buf_size) {
186
+ growBuffer(buf, 10);
187
+ }
188
+ len += xmlCopyChar(0, &buf[len], val);
189
+ @@ -3835,7 +3836,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
190
+ ctxt->nbentities += ent->owner;
191
+ if ((ent != NULL) &&
192
+ (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
193
+ - if (len > buf_size - 10) {
194
+ + if (len + 10 > buf_size) {
195
+ growBuffer(buf, 10);
196
+ }
197
+ if ((ctxt->replaceEntities == 0) &&
198
+ @@ -3863,7 +3864,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
199
+ current++;
200
+ } else
201
+ buf[len++] = *current++;
202
+ - if (len > buf_size - 10) {
203
+ + if (len + 10 > buf_size) {
204
+ growBuffer(buf, 10);
205
+ }
206
+ }
207
+ @@ -3871,7 +3872,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
208
+ rep = NULL;
209
+ }
210
+ } else {
211
+ - if (len > buf_size - 10) {
212
+ + if (len + 10 > buf_size) {
213
+ growBuffer(buf, 10);
214
+ }
215
+ if (ent->content != NULL)
216
+ @@ -3899,7 +3900,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
217
+ * Just output the reference
218
+ */
219
+ buf[len++] = '&';
220
+ - while (len > buf_size - i - 10) {
221
+ + while (len + i + 10 > buf_size) {
222
+ growBuffer(buf, i + 10);
223
+ }
224
+ for (;i > 0;i--)
225
+ @@ -3912,7 +3913,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
226
+ if ((len != 0) || (!normalize)) {
227
+ if ((!normalize) || (!in_space)) {
228
+ COPY_BUF(l,buf,len,0x20);
229
+ - while (len > buf_size - 10) {
230
+ + while (len + 10 > buf_size) {
231
+ growBuffer(buf, 10);
232
+ }
233
+ }
234
+ @@ -3921,7 +3922,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
235
+ } else {
236
+ in_space = 0;
237
+ COPY_BUF(l,buf,len,c);
238
+ - if (len > buf_size - 10) {
239
+ + if (len + 10 > buf_size) {
240
+ growBuffer(buf, 10);
241
+ }
242
+ }
243
+ @@ -3946,7 +3947,18 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
244
+ }
245
+ } else
246
+ NEXT;
247
+ - if (attlen != NULL) *attlen = len;
248
+ +
249
+ + /*
250
+ + * There we potentially risk an overflow, don't allow attribute value of
251
+ + * lenght more than INT_MAX it is a very reasonnable assumption !
252
+ + */
253
+ + if (len >= INT_MAX) {
254
+ + xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
255
+ + "AttValue lenght too long\n");
256
+ + goto mem_error;
257
+ + }
258
+ +
259
+ + if (attlen != NULL) *attlen = (int) len;
260
+ return(buf);
261
+
262
+ mem_error:
263
+ --
264
+ 1.8.4.1
265
+
@@ -0,0 +1,102 @@
1
+ From 64d7de23165b706510f4ce4f29d96552eeb257d7 Mon Sep 17 00:00:00 2001
2
+ From: Daniel Veillard <veillard@redhat.com>
3
+ Date: Wed, 18 Jul 2012 11:38:17 +0800
4
+ Subject: [PATCH 2/9] Fix entities local buffers size problems
5
+
6
+ [Origin: 4f9fdc709c4861c390cd84e2ed1fd878b3442e28]
7
+ ---
8
+ entities.c | 36 +++++++++++++++++++++++-------------
9
+ 1 file changed, 23 insertions(+), 13 deletions(-)
10
+
11
+ diff --git a/entities.c b/entities.c
12
+ index 6aef49f..859ec3b 100644
13
+ --- a/entities.c
14
+ +++ b/entities.c
15
+ @@ -528,13 +528,13 @@ xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) {
16
+ * Macro used to grow the current buffer.
17
+ */
18
+ #define growBufferReentrant() { \
19
+ - buffer_size *= 2; \
20
+ - buffer = (xmlChar *) \
21
+ - xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \
22
+ - if (buffer == NULL) { \
23
+ - xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");\
24
+ - return(NULL); \
25
+ - } \
26
+ + xmlChar *tmp; \
27
+ + size_t new_size = buffer_size *= 2; \
28
+ + if (new_size < buffer_size) goto mem_error; \
29
+ + tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
30
+ + if (tmp == NULL) goto mem_error; \
31
+ + buffer = tmp; \
32
+ + buffer_size = new_size; \
33
+ }
34
+
35
+
36
+ @@ -555,7 +555,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
37
+ const xmlChar *cur = input;
38
+ xmlChar *buffer = NULL;
39
+ xmlChar *out = NULL;
40
+ - int buffer_size = 0;
41
+ + size_t buffer_size = 0;
42
+ int html = 0;
43
+
44
+ if (input == NULL) return(NULL);
45
+ @@ -574,8 +574,8 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
46
+ out = buffer;
47
+
48
+ while (*cur != '\0') {
49
+ - if (out - buffer > buffer_size - 100) {
50
+ - int indx = out - buffer;
51
+ + size_t indx = out - buffer;
52
+ + if (indx + 100 > buffer_size) {
53
+
54
+ growBufferReentrant();
55
+ out = &buffer[indx];
56
+ @@ -692,6 +692,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
57
+ }
58
+ *out = 0;
59
+ return(buffer);
60
+ +
61
+ +mem_error:
62
+ + xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");
63
+ + xmlFree(buffer);
64
+ + return(NULL);
65
+ }
66
+
67
+ /**
68
+ @@ -709,7 +714,7 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
69
+ const xmlChar *cur = input;
70
+ xmlChar *buffer = NULL;
71
+ xmlChar *out = NULL;
72
+ - int buffer_size = 0;
73
+ + size_t buffer_size = 0;
74
+ if (input == NULL) return(NULL);
75
+
76
+ /*
77
+ @@ -724,8 +729,8 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
78
+ out = buffer;
79
+
80
+ while (*cur != '\0') {
81
+ - if (out - buffer > buffer_size - 10) {
82
+ - int indx = out - buffer;
83
+ + size_t indx = out - buffer;
84
+ + if (indx + 10 > buffer_size) {
85
+
86
+ growBufferReentrant();
87
+ out = &buffer[indx];
88
+ @@ -774,6 +779,11 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
89
+ }
90
+ *out = 0;
91
+ return(buffer);
92
+ +
93
+ +mem_error:
94
+ + xmlEntitiesErrMemory("xmlEncodeSpecialChars: realloc failed");
95
+ + xmlFree(buffer);
96
+ + return(NULL);
97
+ }
98
+
99
+ /**
100
+ --
101
+ 1.8.4.1
102
+
@@ -0,0 +1,26 @@
1
+ From 83bbfdfe1e804f8cdc72b86742364cf045dd8678 Mon Sep 17 00:00:00 2001
2
+ From: Aron Xu <happyaron.xu@gmail.com>
3
+ Date: Fri, 20 Jul 2012 15:41:34 +0800
4
+ Subject: [PATCH 3/9] Fix an error in previous commit
5
+
6
+ [Origin: baaf03f80f817bb34c421421e6cb4d68c353ac9a]
7
+ ---
8
+ entities.c | 2 +-
9
+ 1 file changed, 1 insertion(+), 1 deletion(-)
10
+
11
+ diff --git a/entities.c b/entities.c
12
+ index 859ec3b..7d06820 100644
13
+ --- a/entities.c
14
+ +++ b/entities.c
15
+ @@ -529,7 +529,7 @@ xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) {
16
+ */
17
+ #define growBufferReentrant() { \
18
+ xmlChar *tmp; \
19
+ - size_t new_size = buffer_size *= 2; \
20
+ + size_t new_size = buffer_size * 2; \
21
+ if (new_size < buffer_size) goto mem_error; \
22
+ tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
23
+ if (tmp == NULL) goto mem_error; \
24
+ --
25
+ 1.8.4.1
26
+
@@ -0,0 +1,26 @@
1
+ From c8385ccac9e9723a1f87da1c29da56d97df4af85 Mon Sep 17 00:00:00 2001
2
+ From: Daniel Veillard <veillard@redhat.com>
3
+ Date: Mon, 29 Oct 2012 10:39:55 +0800
4
+ Subject: [PATCH 4/9] Fix potential out of bound access
5
+
6
+ [Origin: 6a36fbe3b3e001a8a840b5c1fdd81cefc9947f0d]
7
+ ---
8
+ parser.c | 2 +-
9
+ 1 file changed, 1 insertion(+), 1 deletion(-)
10
+
11
+ diff --git a/parser.c b/parser.c
12
+ index 9863275..e1b0364 100644
13
+ --- a/parser.c
14
+ +++ b/parser.c
15
+ @@ -3932,7 +3932,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
16
+ c = CUR_CHAR(l);
17
+ }
18
+ if ((in_space) && (normalize)) {
19
+ - while (buf[len - 1] == 0x20) len--;
20
+ + while ((len > 0) && (buf[len - 1] == 0x20)) len--;
21
+ }
22
+ buf[len] = 0;
23
+ if (RAW == '<') {
24
+ --
25
+ 1.8.4.1
26
+