sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Alloc-dealloc-mismatch in yydestruct at bison_parser.y:172

Open bladchan opened this issue 1 year ago • 1 comments

Here is my example.cpp which how I used this library.

// example.cpp
#include "hsql/SQLParser.h"

int main(int argc, char** argv) {
	
	const std::string query = "INSERT INTO Websites (name, url, alexa, country) nALUES ('baidu','httWebsites (nps://www.baidu.com/','4','CN');";
	hsql::SQLParserResult result;
    	hsql::SQLParser::parse(query, &result);
	
	if (result.isValid() && result.size() > 0) {
        	const hsql::SQLStatement* statement = result.getStatement(0);
	}
}

I used the address sanitizer(ASAN), but asan reported an alloc-dealloc-mismatch issue.

ASAN said that:

$ ./example
=================================================================
==54914==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x602000000050
    #0 0x513ad8 in operator delete(void*) (/home/ubuntu/some_c_test/sql-parser/fuzz/test+0x513ad8)
    #1 0x7f1f94bc28b0 in yydestruct(char const*, int, HSQL_STYPE*, HSQL_CUST_LTYPE*, hsql::SQLParserResult*, void*) /home/ubuntu/some_c_test/sql-parser/bison_parser.y:172:11
    #2 0x7f1f94bb7b65 in hsql_parse(hsql::SQLParserResult*, void*) /home/ubuntu/some_c_test/sql-parser/bison_parser.cpp:5290:7
    #3 0x7f1f94b9afed in hsql::SQLParser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, hsql::SQLParserResult*) /home/ubuntu/some_c_test/sql-parser/src/SQLParser.cpp:27:13
    #4 0x5173e5 in main /home/ubuntu/some_c_test/sql-parser/fuzz/./test.c:7:6
    #5 0x7f1f937c0c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
    #6 0x41a8f9 in _start (/home/ubuntu/some_c_test/sql-parser/fuzz/test+0x41a8f9)

0x602000000050 is located 0 bytes inside of 5-byte region [0x602000000050,0x602000000055)
allocated by thread T0 here:
    #0 0x436fd0 in strdup (/home/ubuntu/some_c_test/sql-parser/fuzz/test+0x436fd0)
    #1 0x7f1f94c17daf in hsql_lex(HSQL_STYPE*, HSQL_CUST_LTYPE*, void*) /home/ubuntu/some_c_test/sql-parser/flex_lexer.l:264:18
    #2 0x7f1f94ba57f9 in hsql_parse(hsql::SQLParserResult*, void*) /home/ubuntu/some_c_test/sql-parser/bison_parser.cpp:2947:16
    #3 0x7f1f94b9afed in hsql::SQLParser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, hsql::SQLParserResult*) /home/ubuntu/some_c_test/sql-parser/src/SQLParser.cpp:27:13
    #4 0x5173e5 in main /home/ubuntu/some_c_test/sql-parser/fuzz/./test.c:7:6
    #5 0x7f1f937c0c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/home/ubuntu/some_c_test/sql-parser/fuzz/test+0x513ad8) in operator delete(void*)
==54914==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==54914==ABORTING

bladchan avatar Sep 23 '22 09:09 bladchan

Thank you for raising this issue, we opened a PR that aims to fix the alloc-dealloc-mismatch.

dey4ss avatar Sep 23 '22 09:09 dey4ss

@bladchan The issue should be fixed now, feel free to reopen the issue if you still encounter problems.

dey4ss avatar Oct 17 '22 14:10 dey4ss