Repository navigation
fix: reject -db containing only commas or empty names instead of panic - #59
Conversation
When -db is non-empty but every comma-separated item trims to empty (e.g. -db ',,'), opt.dbs ends up empty and dumpData panics with 'index out of range' accessing opt.dbs[0]. Validate the parsed list during option parsing and return a controlled 'invalid input' error (exit code 1), consistent with other invalid input handling. Fixes matrixorigin/matrixone#30573
Extract the -db parsing/validation into parseDatabases() and cover it: - unit tests over comma/blank-only, mixed and valid lists - process-level tests asserting exit code 1, controlled 'modump error' on stderr, empty stdout and no panic for invalid lists, and that a list containing a valid name still passes -db validation Note: Test_toCsvLine fails on the base commit as well and is unrelated to this change.
-P 1 only assumed the connection would fail; a service accepting the handshake on that port would let the dump proceed and emit output, making the empty-stdout assertion flaky. Use -h ':' instead: the host validation runs after -db parsing and before any connection, so it deterministically proves the mixed list passed -db validation.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
APPROVE at 428a937 (base 324c33d).
The database-list parser remains the single validation owner. Empty normalized lists now fail before dumpData indexes dbs[0], while valid comma-separated lists preserve existing behavior. The subprocess tests exercise real main, exact exit status/stderr/stdout, and the valid-list control deterministically reaches the later host validation without network I/O. No compatibility branch or unnecessary production abstraction was added.
All changed hunks reviewed. Independent package run: 31 passing test/subtest events and only the two independently base-confirmed CSV failures. Standalone build, vet, gofmt and diff checks pass. No unresolved actionable comments or additional blocker found. No subagents or source edits.
Resolve import conflict in cmd/mo-dump/main_test.go: upstream removed the encoding/csv import; keep only the flag import needed by the helper process tests.
Resolve import conflict in cmd/mo-dump/main_test.go: keep both encoding/hex (upstream tests) and flag (helper process tests).
Resolve conflicts in cmd/mo-dump/main_test.go: - imports: keep both os/exec usage sides, add upstream path/filepath - keep both new test blocks: our -db validation tests and upstream export/exit-status tests
…trip-305xx Resolve cmd/mo-dump/main.go conflicts against main's bufio-based CSV writer (#57/#59) and the #30638 INSERT-header fix (#62), and harden the #30587 sql_mode pin: - imports: keep strconv/math for the float overflow/-0 CAST path (#30598); main's regexp/encoding-csv removals retained. - toCsv tail: take main's r.Err()+w.Flush(), which already covers the #30628 final-flush error; drop the csvWriter.Error() alternative. - showLoad: keep plain-name CSV reference (#30481), sqlStringLiteral quoting of path/delimiter (#30590) and the explicit Close() error check (#30628). - sql_mode pin (#30587): emit once at the top of the script instead of inside the per-database all-tables block. A multi-database dump previously overwrote @MODUMP_SAVED_SQL_MODE with the already-stripped mode, so the end-of-script restore restored the wrong value; -tbl dumps skipped the pin entirely. - sql_mode strip: remove NO_BACKSLASH_ESCAPES from a comma-wrapped list via TRIM(BOTH ',' FROM REPLACE(CONCAT(',',mode,','),',NO_BACKSLASH_ESCAPES,',',')) so it cannot leave an invalid empty token ('X,' / ',X' / 'X,,Y') at any position of the mode.
What type of PR is this?
Which issue(s) this PR fixes:
issue matrixorigin/matrixone#30573
What this PR does / why we need it:
For inputs like
mo-dump -db ',,', the raw-dbstring is non-empty, so it passes thelen(opt.database) == 0check.However, after splitting by comma and filtering out empty items,
opt.dbsends up as an empty slice, anddumpDatathenpanics with
index out of range [0] with length 0when accessingopt.dbs[0](exit code 2).This PR adds a validation right after parsing
-db: if no valid database name remains after filtering, it returns acontrolled
invalid inputerror (modump error: ...on stderr, exit code 1) instead of panicking — consistent with howother invalid inputs (e.g. a two-character csv field delimiter) are handled.
Verification
make buildpasses.mo-dump -db ',,',mo-dump -db ',',mo-dump -db ' , , ',mo-dump -db ''all print a controlledmodump error: invalid input: ...with exit code 1 and no panic.mo-dump -db 'testdb,, 'still passes argument validation and behaves as before afterwards.