db.connect: reject overlong database names before fixed-buffer copies#7424
db.connect: reject overlong database names before fixed-buffer copies#7424orbisai0security wants to merge 10 commits into
Conversation
Automated security fix generated by OrbisAI Security
|
Before going further, can the new test file be in the correct directory according to our repo-specific conventions: see AGENTS.md |
|
Thanks, that makes sense. I’ll move the test under the module-specific test directory and align the filename with the repository conventions in AGENTS.md. I also agree that the current framing is too strong. I’ll revise the PR description from “critical security issue” to “defensive hardening / bounds-safety fix” unless we can demonstrate a reachable external input path for an oversized databaseName. One question before I amend: would you prefer the C change to preserve the current behaviour with bounded truncation via snprintf(), or should oversized expanded database paths be rejected explicitly with G_fatal_error()? I lean toward explicit rejection because silent truncation of a database path could be surprising. |
Fine !
If the changes to explicitly reject are too big or too different, I would lean to keep the existing behaviour, for easier review, since this is an AI-PR, and keeping similar code is easier to reason about. Otherwise, rejection seems like the correct behaviour to not try to connect to an unexpected database. |
…ation Address code review feedback from PR OSGeo#7424: - Add explicit G_fatal_error() checks for buffer overflow instead of silent truncation, following established GRASS pattern (lib/init/clean_temp.c:62, lib/vector/Vlib/open.c:1484-1490) - Move test from /tests/ to db/db.connect/tests/ following repository conventions (AGENTS.md) - Rename test file to db_connect_buffer_overflow_test.py to match module naming pattern Prevents connecting to truncated/incorrect database paths when expanded paths exceed GPATH_MAX. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
I've made these changes, pls review! |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
@orbisai0security Please address the tests issues in your PR |
Replace the Python simulation test with proper integration tests that call the actual db.connect C module. Add conftest.py with GRASS session fixture required for pytest. Changes: - Add db/db.connect/tests/conftest.py with module-scoped session fixture - Replace Python simulation with 5 focused integration tests: 1. Normal database names work 2. Long but valid names work 3. Overlong names are rejected with G_fatal_error 4. Variable expansion overflow is caught 5. Normal variable expansion works correctly The previous test simulated buffer behavior in Python without calling the actual C code, providing no security assurance. These integration tests verify the actual snprintf bounds checking in main.c lines 336-394. Addresses code review feedback on PR OSGeo#7424. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Summary
This PR hardens
db.connectby adding explicit bounds handling before copying the configured database name into fixed-sizeGPATH_MAXbuffers.The previous code used unbounded
strcpy()when copyingconn->databaseNameand intermediate values into fixed-size buffers. This patch replaces those copies with bounded handling so oversized database names cannot write past the destination buffer.Changes
strcpy()calls indb/db.connect/main.cwith bounded copies.GPATH_MAX.AGENTS.md.Rationale
This is a defensive hardening and robustness improvement. It avoids relying on callers or configuration paths to always provide values shorter than
GPATH_MAX.I am not claiming a demonstrated externally reachable exploit path here; the goal is to make the local invariant explicit: values copied into
GPATH_MAXbuffers must either fit or be rejected/truncated safely.Testing
Verification
Security Invariant
Regression test
This test guards against regressions — it's useful independent of the code change above.
Automated security fix by OrbisAI Security