Commit e8751fb
authored
Fix PostgreSQL product creation with special characters in DB name (#4830)
* routing: add PostgreSQL database name validator
Introduces is_valid_postgresql_db_name, a permissive validator that
rejects database names that would break a CREATE DATABASE statement
or corrupt a connection string (quotes, semicolons, whitespace, null
and control characters, or names longer than PostgreSQL's 63-byte
identifier limit).
The validator is intentionally permissive: names that are legal only
as quoted identifiers (e.g. 'test-product', '1team', 'user') are
accepted because CodeChecker will quote the identifier when issuing
CREATE DATABASE. See the companion commit wiring the validator into
addProduct() and fixing the CREATE DATABASE statement.
Unit-tested in test_request_routing.py.
* product: fix CREATE DATABASE failure on special characters
The PostgreSQL path of _create_database() interpolated the user-supplied
database name directly into a CREATE DATABASE statement via an f-string.
This caused syntax errors for any name that is not a legal unquoted
PostgreSQL identifier - in particular names containing a dash
(e.g. 'test-product') or starting with a digit (e.g. '1team') - both
reported by users via the GUI's product creation dialog.
SQLAlchemy does not auto-quote identifiers in free-form text() clauses,
so the fix has two parts:
* Quote the identifier explicitly using the dialect's
IdentifierPreparer before embedding it in the statement. This
produces a properly double-quoted name such as CREATE DATABASE
"test-product", which PostgreSQL accepts.
* Validate the database name in addProduct() using the new
is_valid_postgresql_db_name() helper, so that inputs containing
quotes, semicolons, whitespace, control characters, or that
exceed PostgreSQL's 63-byte identifier limit are rejected with a
clear error message before any SQL is issued, rather than crashing
later with an opaque driver error.
* address review: move validator to codechecker_common.util
Per #4830 review feedback: is_valid_postgresql_db_name belongs with
the other generic helpers in codechecker_common.util, not in the web
server's routing module. The function and its tests are unchanged;
only the import paths in product_server.py and test_request_routing.py
are adjusted.1 parent 621ca85 commit e8751fb
3 files changed
Lines changed: 116 additions & 2 deletions
File tree
- codechecker_common
- web/server
- codechecker_server/api
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
370 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
371 | 375 | | |
372 | 376 | | |
373 | 377 | | |
| |||
410 | 414 | | |
411 | 415 | | |
412 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
413 | 430 | | |
414 | 431 | | |
415 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
0 commit comments