Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy 5.7.20 crashes if allocator replaced #797

Closed
dd8 opened this issue Jan 28, 2019 · 5 comments
Closed

Tidy 5.7.20 crashes if allocator replaced #797

dd8 opened this issue Jan 28, 2019 · 5 comments
Labels

Comments

@dd8
Copy link

dd8 commented Jan 28, 2019

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

@geoffmcl
Copy link
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...

@geoffmcl geoffmcl added the Bug label Jan 28, 2019
@dd8
Copy link
Author

dd8 commented Jan 28, 2019

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

@geoffmcl
Copy link
Contributor

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

@dd8
Copy link
Author

dd8 commented Jan 29, 2019

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

@geoffmcl
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants