Skip to content

Decoding, validation, and path-resolution fixes for cgi-bin scripts - #3

Merged
lonvia merged 19 commits into
fossgis:masterfrom
b1tw153:b1tw153/improve-cgi-scripts
Oct 25, 2026
Merged

lonvia merged 19 commits into
fossgis:masterfrom
b1tw153:b1tw153/improve-cgi-scripts

Conversation

@b1tw153

@b1tw153 b1tw153 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

This is upstream drolbr#796.

The v0.7.62.1 import removed src/cgi-bin/augmented_map, src/cgi-bin/ping and src/cgi-bin/sitemap. Commits 4bbd2903, 494faace and 29ac83e4 on this branch edit those scripts. The last commit deletes them again so the branch merges cleanly. Their edits do not appear in "Files changed".

src/cgi-bin/*

  • Pipe the raw parameter values to uncgi on stdin using printf '%s' to ensure that they are correctly decoded.
  • Resolve the script's own path and relative paths with realpath to ensure that path construction is correct.
  • Validate parameters before use. Data-API scripts return 400 for a malformed request and 500 only for a missing or unreadable backend file. Scripts that render an HTML page fall back to defaults instead of erroring.
  • kill_my_queries: validate the PID argument; construct paths more carefully.
  • Quoting, ShellCheck, and backtick → $( ) fixes throughout.

Scripts accept the same inputs and produce the same outputs as before for
well-formed requests.

src/pt_diagrams/uncgi.cc

  • Properly handle a trailing % at the end of the input.
  • Restructure main input loop to ensure the entire input is read correctly.

uncgi accepts the same inputs and produces the same outputs as before for
well-formed requests.

b1tw153 added 19 commits July 10, 2026 08:27
The v0.7.62.1 release removed these scripts. Earlier commits on this
branch modified them. Deleting them lets the branch merge into a tree
that includes the release.
@lonvia
lonvia merged commit 284d0d1 into fossgis:master Oct 25, 2026
lonvia pushed a commit that referenced this pull request Nov 30, 2026
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:

  stdin.log    the query (for a CGI test, the request body, if any)
  init.osm     optional: data imported into a database of the test's own
  import.args  optional: arguments for update_database (default --meta)
  env          optional: run cgi-bin/interpreter with these environment
               variables instead of osm3s_query, with a dispatcher over
               the test's database

As in the other suites, stderr is compared only for a test that has an
expected stderr.log, which only tests that expect an error need, and
remarks and timings in it are ignored.

Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite: either limit
adds a note to stdout.log. The database is created with mktemp, because
the dispatcher's socket path in a directory under osm-3s_testing/run can
exceed the length limit for socket paths. The script passes shellcheck.

The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, the scope of the "=" search, the
operates_* checks in pt_diagrams), the cgi-bin shell scripts of #3,
and the performance changes of #8 and #11.

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
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