fix(db2): escape SQL identifiers and literals in metadata/DDL paths (#1914) - #2173
Merged
Conversation
Contributor
Author
|
Converting to draft: final adversarial review pass is still in progress for this branch. Will mark ready for review once it completes. (process note: PR was opened prematurely by automation) |
HandSonic
marked this pull request as ready for review
July 26, 2026 10:28
HandSonic
marked this pull request as draft
July 26, 2026 10:57
HandSonic
marked this pull request as ready for review
July 26, 2026 11:33
…aths (OtterMind#1914) - buildCreateColumnSql fallback: validate columnType against a strict type-shape whitelist and escape the column name as a delimited identifier instead of delegating to the raw SPI buildDefaultColumn - tableDDL: reject schema/table names containing double quotes, which would otherwise break out of the db2look -td/-t option string - add regression tests for both paths plus SET SCHEMA, dropTable and copyTable escaping composition
…t validation (OtterMind#1914) - DB2SqlBuilder: override buildDropTable/buildTruncateTable so qualified table names are quoted via Db2SqlEscapes instead of the SPI identity - DB2DBManager: override truncateTable with the same quoting - DB2ColumnTypeEnum.getByType: strip size suffix so VARCHAR(10) resolves to the enum and reaches the validated fallback instead of being skipped - DB2ColumnTypeEnum: drop parens/comma from DEFAULT_VALUE_PATTERN to block column-definition breakout via crafted default values - add regression tests for all four paths
…ayloads (OtterMind#1914) - DEFAULT_VALUE_PATTERN: drop single-quote from the allowed class so crafted defaults cannot toggle string-literal context inside the enclosing CREATE/ALTER statement - anchor DEFAULT_VALUE_PATTERN, UNIT_PATTERN and FALLBACK_COLUMN_TYPE_PATTERN with \A/\z instead of ^/$ so a trailing newline can no longer smuggle input past validation - validateAscOrDesc needs no anchor change: it uses exact string equality, which is already absolute - add rejection tests for quote/comma/paren breakout defaults, trailing-newline bypasses, and GET_DDL_TOKEN option-string quoting
…er review (OtterMind#1914) - new Db2IdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier with double-quote doubling, escapeString with single-quote doubling - DB2MetaData overrides getSQLIdentifierProcessor(); metadata call sites use it - builders/managers/enums use Db2IdentifierProcessor.INSTANCE - non-escapable validation moved to Db2SqlGuards (default values, length units, fallback column types, index sort directions) - Db2SqlEscapes removed; tests migrated (23 green)
openai0229
approved these changes
Jul 29, 2026
openai0229
left a comment
Contributor
There was a problem hiding this comment.
Maintainer review complete. Identifier round-trip, DB2 case folding, legal default expressions, and db2look parameter binding were corrected; clean DB2 reactor tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Closes #1914
Summary
Escapes DB2 identifiers and SQL string literals throughout metadata, export, and DDL-generation paths.
Affected surfaces
Verification
mvn -B -f chat2db-community-server/pom.xml -pl chat2db-community-plugins/chat2db-community-db2 -am -Dmaven.test.skip=false -DskipTests=false clean test->BUILD SUCCESS; DB2 tests 29/29 passed, with all upstream reactor tests passing.Risk and compatibility
Reviewer map
Db2IdentifierProcessor,Db2SqlGuards, andDb2IdentifierProcessorTest.DB2LK_GENERATE_DDL.Contributor declaration
AI assistance: Codex was used for maintainer review, implementation corrections, and test updates.