babelfish-for-postgresql / babelfish_extensions

Babelfish for PostgreSQL provides the capability for PostgreSQL to work with applications written for Microsoft SQL Server. Babelfish understands the SQL Server wire-protocol and T-SQL, the Microsoft SQL Server query and procedural language, so you don’t have to switch database drivers or rewrite all of your application queries.
https://babelfishpg.org/
Apache License 2.0
274 stars 93 forks source link

Fixed implementation of remove_accents_internal to better manage the memory #2643

Closed Deepesh125 closed 4 months ago

Deepesh125 commented 4 months ago

In previous implementation of remove_accents_internal, we were passing input string to utrans_transUChars which will modify the string in place in order to remove the accents. And memory for the input string was also not well allocated in order to accommodate this expansion of string by utrans_transUChars causing the function to write out of allocated heap. This may cause various issues, for example,

  1. Error like "pfree called with invalid pointer 0x149fb5b3c050 (header 0x0069032703270327)"
  2. warnings like "problem in alloc set ExprContext: detected write past chunk end in block 0x35c6770, chunk 0x35c67e8" and "detected write past chunk end in ExprContext 0x2b24f48"
  3. even result in server crash while allocating or freeing the memory

This commit fixes the implementation of remove_accents_internal to rightly calculate the capacity and allocate the enough memory to input string to handle possible expansion of the string by utrans_transUChars.

Task: BABEL-5006

Check List

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 commented 4 months ago

Pull Request Test Coverage Report for Build 9365821766

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/collation.c 12 14 85.71%
<!-- Total: 12 14 85.71% -->
Totals Coverage Status
Change from base Build 9314670965: 0.002%
Covered Lines: 41723
Relevant Lines: 57002

💛 - Coveralls