kjdev / hoextdown

Hoextdown is an extension to Hoedown
MIT License
23 stars 15 forks source link

Use-after-free when computing block attributes #54

Open Sjlver opened 6 years ago

Sjlver commented 6 years ago

Problem: hoedown's block_attr may outlive the buffers that it is computed from.

Consider the following test case:

- Some text{@list #foo}
- More text. This needs to be sufficiently long, so that the work buffer
  storing the list items is re-allocated.

When parsing the list in parse_list, hoedown creates a new attr buffer to store the list's attributes. This buffer is a read-only view into the original src buffer.

List items are then parsed by parse_list_item. This function creates its own work buffer and copies the list items into that work buffer.

When parse_list_item parses block attributes, it makes the original attr buffer point at data in its work buffer.

Once the list items have been parsed, the work buffer is freed. Now, attr points at data that is no longer valid.

Problematic places are: