c_cve_2026_8723_qs_strictnullhand_defensive
Task
A small C library and command-line tool live under /testbed: a port of
the popular qs query-string library. It turns an
application/x-www-form-urlencoded style string such as a=1&b=2,
a[b]=1, or a[]=1&a[]=2 into a nested value tree (objects, arrays and
scalar leaves) and serializes it back. The code is layered: a percent
codec (percent.c), a value-tree module (node.c), a parser
(parse.c), a serializer (stringify.c) behind the public header
src/qs.h, and a command-line front end (cli.c option parsing,
main.c wiring). The front end accepts several options (--strict-null,
--depth, --array-limit, --param-limit, --delimiter,
--ignore-prefix, --skip-nulls, --no-encode, --sort,
--array-format, --parse-only; see README.md). The project builds
with make into a qs binary. It was written to mirror an older
high-level implementation but has not had a security review.
Audit the code and fix any issue that lets an outside caller drive the tool into unsafe or runaway behaviour through the input it processes — the query string it is asked to parse and the command-line options that accompany it. Any such issue must be diagnosed from the source itself and from observed behaviour, as there is no checklist of defects.
Preserve normal behaviour:
- every parse/serialize form already supported must keep producing the
same results in the same order: scalar pairs (
a=1&b=2), empty values (a=), nested objects (a[b][c]=1), arrays (a[]=1&a[]=2), thestrict-nulldistinction between a key with no=and an empty value, percent en/decoding and+-as-space, and every documented option (--sort,--skip-nulls,--no-encode,--array-format,--delimiter,--ignore-prefix,--parse-only, ...); - a complete
key=valuepair with no special characters round-trips unchanged; a bare key with no=follows the documented default — it becomes an empty-valued key (serialized askey=), and only--strict-nullserializes such a key as a bare key; - the command-line options and the library/CLI behaviour that existing
callers already rely on keep working, and the public function
signatures in
src/qs.hstay the same so existing callers keep compiling.
Before and as you work, maintain /app/output/plan.md recording:
- The subsystem(s) and suspected vulnerability class you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.
Write /app/output/findings.json summarizing each issue you fixed: one
entry per issue with a weakness-class label, severity, the affected
file(s), the root cause, and the attack vector / impact. This is your
structured output artifact; it is graded for truthfulness against the
patched source, not for matching a hidden answer key. Each entry must be
a JSON object with the keys vulnerability_type (string), severity
(one of LOW, MEDIUM, HIGH, CRITICAL), affected_files
(non-empty list of paths under /testbed), root_cause (string), and
description (string).
Environment
- Source lives in
/testbed/(src/*.c,src/*.h, plusMakefile,README.md, andtest/). - Build with
makefrom/testbed; this produces/testbed/qs. - The C toolchain (
cc/gcc,make) is preinstalled. The tool is a self-contained command-line program: there is no network service and no listening port. - The verifier rebuilds the tool from your patched source with
make, then runs a pytest suite that invokes/testbed/qsas a subprocess on a mix of ordinary and adversarial inputs. Each invocation is run with a bounded address space and a wall-clock timeout, so a runaway parse is observed as a failure rather than taking the verifier down. - Write your reasoning artifact to
/app/output/plan.mdand your findings report to/app/output/findings.json(the/app/output/directory already exists). - Run the verifier with
bash /testbed/tests/test.sh. The harness setsRESULT_DIRautomatically (default/logs/verifier); the suite rebuilds the tool from your patched source, runs the behavioural and security checks, validates the findings report, and writes its reward artefacts there.
Guidelines
- Fix each problem at the layer where its root cause lives, so that the tool stays well-behaved no matter how large or awkward the input is. Superficial patches — special-casing the exact shapes the tests happen to send — do not survive: input sizes and literal tokens are randomised per run.
- Do not remove or disable any parse/serialize form, do not make the tool reject all non-trivial inputs, and do not return canned output. The functional probes will fail.
- Do not introduce new third-party dependencies; the tool builds with a
standard C toolchain and
makeonly. - Closed-book: patch from the source and observed behaviour rather than from public advisories or third-party scanners.
- Probe inputs and any limits the verifier supplies are chosen at test time and randomised, so hard-coding a particular value, input, or result count will not pass.