hyrise / sql-parser

SQL Parser for C++. Building C++ object structure from SQL statements.
MIT License
749 stars 243 forks source link

Segmentation fault on inserting values #238

Closed smizonov closed 7 months ago

smizonov commented 7 months ago

Running the following code cause to segfault:

std::string query = "INSERT INTO city (id, name) VALUES (1 'name')";
hsql::SQLParserResult result;
hsql::SQLParser::parse(query, &result);

This sql statement in query is not valid (there is no comma between '1' and 'name'). In this case result.isValid() should return false, but not lead to segfault.

dey4ss commented 7 months ago

Can you please provide some details on how you invoke the example code, your OS, and the compiler? I could not reproduce the segfault by executing your example code or by passing the query to .example/example (clang-17 and AppleClang-15 on macOS 14.4 plus gcc-9, gcc-12, and clang-14 on Ubuntu 22.04).

smizonov commented 7 months ago

Yes, but may be this problem was already fixed. I caught it while using envoy_postgres_filter . This filter use sql-parser. And in case of statements in this issue caught segfault. And as i found, version of sql-parser library, which used in envoy is really old (commit from 2020-06-10).

com_github_envoyproxy_sqlparser = dict(
        project_name = "C++ SQL Parser Library",
        project_desc = "Forked from Hyrise SQL Parser",
        project_url = "https://github.com/envoyproxy/sql-parser",
        version = "3b40ba2d106587bdf053a292f7e3bb17e818a57f",
        sha256 = "96c10c8e950a141a32034f19b19cdeb1da48fe859cf96ae5e19f894f36c62c71",
        strip_prefix = "sql-parser-{version}",
        urls = ["https://github.com/envoyproxy/sql-parser/archive/{version}.tar.gz"],
        use_category = ["dataplane_ext"],
        extensions = [
            "envoy.filters.network.mysql_proxy",
            "envoy.filters.network.postgres_proxy",
        ],
        release_date = "2020-06-10",
        cpe = "N/A",
        license = "MIT",
        license_url = "https://github.com/envoyproxy/sql-parser/blob/{version}/LICENSE",
    ),

Talking about details, i build it using gcc 10.2 on debian 11.

dey4ss commented 7 months ago

Thank you for providing these additional details. First of all, we are always happy to see that our work is used in other projects. It seems that envoy uses a customized fork of our parser: https://github.com/envoyproxy/sql-parser. Thus, as we cannot reproduce the issue on our codebase anymore, please consider opening your issue there.