Skip to content

Buffer overflow in Expat.xs (patch) [rt.cpan.org #19860] #39

@toddr

Description

@toddr

Migrated from rt.cpan.org#19860 (status was 'new')

Requestors:

Attachments:

From on 2006-06-13 09:26:38
:

While looking through the Expat.xs code, I noticed a potential heap
buffer overflow:

Expat.xs, line 498:
  if (cbv->st_serial_stackptr >= cbv->st_serial_stacksize) {
    unsigned int newsize = cbv->st_serial_stacksize + 512;
    Renew(cbv->st_serial_stack, newsize, unsigned int);
    cbv->st_serial_stacksize = newsize;
  }
  cbv->st_serial_stack[++cbv->st_serial_stackptr] =  cbv->st_serial;

Note that in the case (stackptr == stacksize - 1), the stack will NOT be
expanded. Then the new value will be written at location (++stackptr),
which equals stacksize and therefore falls just outside the allocated
buffer.

The bug can be observed using Valgrind when parsing an XML file with
very deep element nesting

A simple fix is to change the test to:
  if (cbv->st_serial_stackptr + 1 >= cbv->st_serial_stacksize) {

Package: XML-Parser-2.34
Perl version: v5.8.5 built for i386-linux-thread-multi
OS: Fedora Core release 3

Bye,
  Joris.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions