Skip to content

Fix #15279 (donate-cpu-server: modernize code and provide REST API) - #9084

Open
danmar wants to merge 2 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:daca-rest-server
Open

danmar wants to merge 2 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:daca-rest-server

Conversation

@danmar

@danmar danmar commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread tools/donate-cpu-server-rest.py Fixed
Comment thread tools/donate-cpu-server-rest.py Fixed

@dmcppcheck dmcppcheck 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.

AI review

I found no significant new problems in the new tools/donate-cpu-server-rest.py. The parsing, the reports and the path checks match what donate-cpu-server.py does as far as I could check.

The one new issue is minor and I checked it by reasoning, not by running the server. On the name detail pages (/check_library-…, /unknown_macro-…, /incomplete_var-…), the "packages.txt" link comes from request.url.path, which is already percent-decoded. The handler then decodes the path again with unquote_plus. For a name that contains a literal +, the link therefore asks for a different name and the list comes back empty.

The PR changes no C/C++ code, and the two CodeQL threads are from a bot, so they get no entries.

Comments

# Comment By Where Status
1 packages.txt link on name pages is decoded twice, so names containing '+' break AI review tools/donate-cpu-server-rest.py:967 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #1.

Testing

  • The PR only adds a Python tool, its test and a CI step, so I did not build cppcheck or testrunner.
  • The server and its tests could not be run. fastapi, uvicorn, jinja2 and httpx are not installed in the container, and with no network and no pip they could not be installed. The new test/tools/donate_cpu_server_rest_test.py would be skipped through importorskip.
  • I put stub fastapi, jinja2, uvicorn and pydantic modules in scratch/stubs so that I could import the module and call the pure functions directly (parse_result, parse_info, safe_path, …).
    • The parser gives the expected results for the header, head and diff sections and for crash stack traces.
    • The crash parser drops the first non-frame line after a stack trace when there is no blank line before it (it reported syntaxError: 1 for two warnings). Real clients only send gdb output for a crash, so this does not seem to matter in practice and I did not report it.
  • Both new files parse with Python 3.7 grammar (ast.parse(..., feature_version=(3,7))). That matters because CI runs py_compile on 3.7 as well.
  • The + problem in the packages.txt link, reproduced by simulating the URL handling:
python3 -c "
import urllib.parse as u
name='operator+()'
href='/check_library-'+u.quote_plus(name); print('link', href)
decoded=u.unquote(href)  # what scope['path'] / request.url.path holds
print('pkgs link', decoded+'?pkgs=1')
print('name parsed from pkgs link', repr(u.unquote_plus(decoded[len('/check_library-'):])))"
link /check_library-operator%2B%28%29
pkgs link /check_library-operator+()?pkgs=1
name parsed from pkgs link 'operator ()'

Automated review of 080b56e by Claude. The pull request was built and tested locally.

def with_query(request: Request, **params: str) -> str:
query = dict(request.query_params)
query.update(params)
return request.url.path + '?' + urllib.parse.urlencode(query)

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.

AI review

request.url.path is built from the percent-decoded scope['path']. On the name detail pages (/check_library-…, /unknown_macro-…, /incomplete_var-…) this link is then decoded a second time by _raw_suffix(), which uses unquote_plus.

For a name that contains a literal +, the report links to /check_library-operator%2B%28%29. The "packages.txt" link built here becomes /check_library-operator+()?pkgs=1, which is read back as the name operator (), so the list is empty.

Fix: build the link from the raw path (request.scope['raw_path']) or quote the path again, for example urllib.parse.quote(request.url.path), keeping + encoded as %2B.

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.

3 participants