Mandarancio / scidown

SciDown processing library in C

Home Page:https://github.com/Mandarancio/scidown/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

base_folder parameter should be copied with strdup in hoedown_document_new()

fabiocolacio opened this issue · comments

I kept running into a double-free error when using Scidown, because apparently the hoedown_document_new does not copy the entire base_folder string, but instead copies the pointer.

This leads to undefined behaviour, because:

  1. If I change the contents of the base_folder string after calling hoedown_document_new (), Scidown will no longer have the correct directory.
  2. If Scidown frees or modify the string when I still need it, my code will act in an undefined way.

This is the problematic line:

doc->base_folder = base_folder;

I would suggest changing it to doc->base_folder = strdup (base_folder)

Also, I would suggest changing the base_folder parameter to be const char* to prevent the string from being corrupted (or at least throw a warning at compile-time).