Skip to content
  • Tyler Hicks's avatar
    parser: Never leave entries list in a bad state · 98ee5a57
    Tyler Hicks authored
    
    
    When merging file entries in process_file_entries(), an error condition
    can leave the entries list in a bad state which can cause invalid reads
    and/or double frees when freeing the codomain and entries list memory.
    
    The problem comes from the need to sort the entries linked list. An
    array of pointers is created to represent the linked list, then the
    array is sorted, then the linked list and the array coexist while the
    entries are merged, then the linked list is reconstructed and the array
    is freed. While the entries are being merged, an error condition can
    occur and the function can return while the linked list is partially
    modified.
    
    The solution is to complete the sorting, reconstruct the linked list,
    and free the array immediately. Once the linked list is in a good state,
    the entries can be merged. Care is taken to adjust the linked list
    pointers as entries are merged. An error condition can occur but the
    linked list is always in a good state and proper cleanup can be
    performed without any memory access issues.
    
    Signed-off-by: default avatarTyler Hicks <tyhicks@canonical.com>
    Acked-by: default avatarSteve Beattie <steve@nxnw.org>
    98ee5a57