Skip to content

Tidy 5.7.20 crashes if allocator replaced #797

Closed

Description

@dd8

attrs.c
DefinePriorityAttribute allocates priorities->list using TidyAlloc(), but re-allocates using realloc() instead of TidyRealloc(), which crashes if TidyAlloc didn't allocate memory via malloc

message.c
DefineMutedMessage allocates list->list using TidyAlloc(), but re-allocates using realloc() instead of TidyRealloc(), which crashes if TidyAlloc didn't allocate memory via malloc

Activity

  1. geoffmcl commented on Jan 28, 2019

    @geoffmcl
    Contributor

    @dd8 thanks for catching this not very obvious bug... but easy to see, when you know what to look for...

    Given that libTidy has a memory TidyAllocator, that users can set to what they want, realloc() should not be used in the raw, in those 2 cases...

    F:\Projects\tidy-html5>find /N ">list" src\*.c
    ---------- SRC\ATTRS.C
    [801]        priorities->list = realloc( priorities->list, sizeof(tmbstr) * priorities->capacity + 1 );
    and
    ---------- SRC\MESSAGE.C
    [1353]        list->list = realloc( list->list, sizeof(tidyStrings) * list->capacity + 1 );
    

    Will try to include this easy fix somewhere... unless someone beats me to it, with say a patch, or PR... thanks...

  2. dd8 commented on Jan 28, 2019

    @dd8
    Author

    I do have a patch which has been tested in production, so I can package that up and attach it to this issue

  3. geoffmcl commented on Jan 28, 2019

    @geoffmcl
    Contributor

    @dd8 that would be appreciated... maybe I can then include it in the next merge I do... thanks...

  4. dd8 commented on Jan 29, 2019

    @dd8
    Author

    Here's the patch
    patch-realloc.diff.txt

    Compiles in XCode 10 clang on Mac, Visual Studio 2015 on Windows
    Tested in production on macOS 10.13, macOS 10.14, Windows 7, Windows 10, Windows Server 2016

    Not tested on Linux/gcc

  5. added a commit that references this issue on Jan 31, 2019
  6. geoffmcl commented on Jan 31, 2019

    @geoffmcl
    Contributor

    @dd8 now applied, version 5.7.22... thanks...

  7. added a commit that references this issue on Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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