Skip to content

fix: reject -db containing only commas or empty names instead of panic - #59

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-30573-main
Oct 22, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-30573-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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 -db string is non-empty, so it passes the len(opt.database) == 0 check.
However, after splitting by comma and filtering out empty items, opt.dbs ends up as an empty slice, and dumpData then
panics with index out of range [0] with length 0 when accessing opt.dbs[0] (exit code 2).

This PR adds a validation right after parsing -db: if no valid database name remains after filtering, it returns a
controlled invalid input error (modump error: ... on stderr, exit code 1) instead of panicking — consistent with how
other invalid inputs (e.g. a two-character csv field delimiter) are handled.

Verification

  • make build passes.
  • mo-dump -db ',,', mo-dump -db ',', mo-dump -db ' , , ', mo-dump -db '' all print a controlled
    modump error: invalid input: ... with exit code 1 and no panic.
  • mo-dump -db 'testdb,, ' still passes argument validation and behaves as before afterwards.

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.
@ck89119
ck89119 marked this pull request as ready for review October 20, 2026 09:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T09:51:05.160851Z 428a937 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mergify

mergify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@XuPeng-SH
XuPeng-SH merged commit f228f16 into matrixorigin:main Oct 22, 2026
@ck89119
ck89119 deleted the issue-30573-main branch October 22, 2026 07:23
aptend added a commit that referenced this pull request Oct 22, 2026
…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.
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.

2 participants