Skip to content

Commit f1bc43b

Browse files
authored
Use size_t for string lengths in ext/xml compat layer (#12808)
This is _not_ exploitable right now because libxml guarantees right now a maximum string length of 1M bytes. But if that limit were to ever change this could overflow in the future leading to exploits. Again, not exploitable right now, but just making it more future-proof.
1 parent 803cd82 commit f1bc43b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/xml/compat.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ _notation_decl_handler(void *user, const xmlChar *notation, const xmlChar *pub_i
311311
}
312312

313313
static void
314-
_build_comment(const xmlChar *data, int data_len, xmlChar **comment, int *comment_len)
314+
_build_comment(const xmlChar *data, size_t data_len, xmlChar **comment, size_t *comment_len)
315315
{
316316
*comment_len = data_len + 7;
317317

@@ -330,16 +330,16 @@ _comment_handler(void *user, const xmlChar *comment)
330330

331331
if (parser->h_default) {
332332
xmlChar *d_comment;
333-
int d_comment_len;
333+
size_t d_comment_len;
334334

335-
_build_comment(comment, xmlStrlen(comment), &d_comment, &d_comment_len);
335+
_build_comment(comment, (size_t) xmlStrlen(comment), &d_comment, &d_comment_len);
336336
parser->h_default(parser->user, d_comment, d_comment_len);
337337
xmlFree(d_comment);
338338
}
339339
}
340340

341341
static void
342-
_build_entity(const xmlChar *name, int len, xmlChar **entity, int *entity_len)
342+
_build_entity(const xmlChar *name, size_t len, xmlChar **entity, size_t *entity_len)
343343
{
344344
*entity_len = len + 2;
345345
*entity = xmlMalloc(*entity_len + 1);
@@ -380,9 +380,9 @@ _get_entity(void *user, const xmlChar *name)
380380
/* Predefined entities will expand unless no cdata handler is present */
381381
if (parser->h_default && ! (ret && ret->etype == XML_INTERNAL_PREDEFINED_ENTITY && parser->h_cdata)) {
382382
xmlChar *entity;
383-
int len;
383+
size_t len;
384384

385-
_build_entity(name, xmlStrlen(name), &entity, &len);
385+
_build_entity(name, (size_t) xmlStrlen(name), &entity, &len);
386386
parser->h_default(parser->user, (const xmlChar *) entity, len);
387387
xmlFree(entity);
388388
} else {

0 commit comments

Comments
 (0)