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

fix valgrind warning in pltsql_store_view_definition #3019

Merged

Conversation

tanscorpio7
Copy link
Contributor

@tanscorpio7 tanscorpio7 commented Oct 14, 2024

Description

Reset static variable original_query_string back to NULL after use otherwise next queries which do not set original_query_string in ANLTR will read already freed memory.

before this change valgrind reports the following error
Root cause here was calls to sp_describe_first_result_set internally creates a view in tsql dialect but we did not set original query string in anltr, which means it will read old already freed value.

==00:04:42:31.158 8517== VALGRINDERROR-BEGIN
==00:04:42:31.158 8517== Invalid read of size 1
==00:04:42:31.158 8517==    at 0x4C32D82: strlen (vg_replace_strmem.c:494)
==00:04:42:31.158 8517==    by 0xB4D3A4: cstring_to_text (varlena.c:187)
==00:04:42:31.158 8517==    by 0x12A2B8F2: pltsql_store_view_definition (hooks.c:3166)
==00:04:42:31.158 8517==    by 0x728494: DefineView (view.c:517)
==00:04:42:31.158 8517==    by 0x9D21C0: ProcessUtilitySlow (utility.c:1666)
==00:04:42:31.158 8517==    by 0x9D0F95: standard_ProcessUtility (utility.c:1095)
==00:04:42:31.158 8517==    by 0x89EC165: call_next_ProcessUtility (tdsutils.c:756)
==00:04:42:31.158 8517==    by 0x89EC0DC: tdsutils_ProcessUtility (tdsutils.c:731)
==00:04:42:31.158 8517==    by 0x8C0C7B3: pgss_ProcessUtility (pg_stat_statements.c:1202)
==00:04:42:31.158 8517==    by 0x12939404: call_prev_ProcessUtility (pl_handler.c:4196)
==00:04:42:31.158 8517==    by 0x129392CD: bbf_ProcessUtility (pl_handler.c:4168)
==00:04:42:31.158 8517==    by 0x9D00B3: ProcessUtility (utility.c:529)
==00:04:42:31.158 8517==  Address 0x17163480 is 2,208 bytes inside a block of size 8,192 alloc'd
==00:04:42:31.158 8517==    at 0x4C2D065: malloc (vg_replace_malloc.c:381)
==00:04:42:31.158 8517==    by 0xBC25CF: AllocSetContextCreateInternal (aset.c:438)
==00:04:42:31.158 8517==    by 0xB9D50E: hash_create (dynahash.c:385)
==00:04:42:31.159 8517==    by 0x129AA76D: create_compile_context (compile_context.c:25)
==00:04:42:31.159 8517==    by 0x12942D5C: pltsql_compile_inline (pl_comp.c:1035)
==00:04:42:31.159 8517==    by 0x1293C51F: pltsql_inline_handler (pl_handler.c:5253)
==00:04:42:31.159 8517==    by 0x89DEFF5: ExecuteSQLBatch (tdssqlbatch.c:94)
==00:04:42:31.159 8517==    by 0x89DF20C: ProcessSQLBatchRequest (tdssqlbatch.c:142)
==00:04:42:31.159 8517==    by 0x89C943A: ProcessTDSRequest (tdsprotocol.c:392)
==00:04:42:31.159 8517==    by 0x89C9F42: TdsSocketBackend (tdsprotocol.c:636)
==00:04:42:31.159 8517==    by 0x89BDF47: pe_process_command (tds_srv.c:450)
==00:04:42:31.159 8517==    by 0x9CC548: PostgresMain (postgres.c:4729)
==00:04:42:31.159 8517== 
==00:04:42:31.159 8517== VALGRINDERROR-END 

Issues Resolved

[BABEL-5246]

Test Scenarios Covered

test_db_collation-* test cases now run clean with valgrind

Sign Off

Signed-off-by: Tanzeel Khan [email protected]

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@coveralls
Copy link
Collaborator

coveralls commented Oct 14, 2024

Pull Request Test Coverage Report for Build 11324827743

Details

  • 7 of 9 (77.78%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 74.485%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/pl_exec.c 7 9 77.78%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tds/src/backend/tds/tdsutils.c 1 73.8%
Totals Coverage Status
Change from base Build 11303200995: -0.003%
Covered Lines: 45153
Relevant Lines: 60620

💛 - Coveralls

@jsudrik jsudrik merged commit 95dbb0b into babelfish-for-postgresql:BABEL_4_X_DEV Oct 14, 2024
46 checks passed
tanscorpio7 added a commit to tanscorpio7/babelfish_extensions that referenced this pull request Oct 14, 2024
…ostgresql#3019)

Reset static variable original_query_string back to NULL after use otherwise next queries which do not set original_query_string in ANLTR will read already freed memory.
---------
Signed-off-by: Tanzeel Khan <[email protected]>
jsudrik pushed a commit that referenced this pull request Oct 15, 2024
Reset static variable original_query_string back to NULL after use otherwise next queries which do not set original_query_string in ANLTR will read already freed memory.
---------
Signed-off-by: Tanzeel Khan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants