Skip to content

tests/server: fix crashing with VS2013 and earlier - #23378

Closed
vszakats wants to merge 6 commits into
curl:masterfrom
vszakats:servers-vs2013
Closed

vszakats wants to merge 6 commits into
curl:masterfrom
vszakats:servers-vs2013

Conversation

@vszakats

@vszakats vszakats commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

The test server code uses plain CRT printf functions, and uses the.
%zd, %zu masks in logmsg() calls. It compiles cleanly with all
supported compilers. But, the CRT of VS2013 (and earlier) do not
actually support these masks, and print zd/zu as-is instead. This by
itself would likely not break tests, but it also leaves the [s]size_t
varargs unconsumed, which crashes the server on the first client
request.

In practice this means that most tests relying on the test server,
failed. With sws, the symptom was a Read zd bytes message in the
log. E.g.: https://ci.appveyor.com/project/curlorg/curl/builds/54869181

Fix by using %ld/%lu, with matching casts.

Test run: https://ci.appveyor.com/project/curlorg/curl/builds/54882859
(remaining failures are unrelated.)

This has been a potential issue since 2008.

Also:

  • dnsd: keep n as signed when printing it in doh_conn_recv().
  • tests/server: enable PRINTFZ checksrc rule for this directory, to
    avoid reintroducing a silent breakage by using these masks.

Bug: #23306 (comment)
Bug: #23306 (comment)
Ref: 7f47b6e #23383
Cherry-picked from #23306


@vszakats vszakats added tests Windows Windows-specific crash labels Oct 12, 2026
@jay

jay commented Oct 12, 2026

Copy link
Copy Markdown
Member

Another way to do this is add a FMT_SIZE_T and FMT_SSIZE_T to curl_setup

/* Older versions of the Windows CRT do not support %zu for size_t so we use %Iu instead */
#ifdef _WIN32
#define FMT_SIZE_T "Iu"
#define FMT_SSIZE_T "Id"
#else
#define FMT_SIZE_T "zu"
#define FMT_SSIZE_T "zd"
#endif

@jay jay mentioned this pull request Oct 12, 2026
9 of 10 tasks
@vszakats

vszakats commented Oct 12, 2026 •

Copy link
Copy Markdown
Member Author

Another way to do this is add a FMT_SIZE_T and FMT_SSIZE_T to curl_setup

/* Older versions of the Windows CRT do not support %zu for size_t so we use %Iu instead */
#ifdef _WIN32
#define FMT_SIZE_T "Iu"
#define FMT_SSIZE_T "Id"
#else
#define FMT_SIZE_T "zu"
#define FMT_SSIZE_T "zd"
#endif

Do you think it's worth it? Is there any logmsg() output in the GiB range
in curl tests?

I find format macros more annoying to maintain, than casts, so I'd pbly only
do it if there is a functional upside. (edit: I still sense a rabbit hole here,
perhaps been tracing / burned by code-wide mask issues too many times.)

(It'd be enough to add the mappings to tests/server/first.h, rest of code
uses curl printf, and examples are not using curl_setup.h.)

@jay

jay commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

I think either way is fine for logmsg in testing because the numbers aren't large, we could even wrap logmsg in win32 and scan for %z in the string and replace with %I before passing to printf if you really wanted the least amount of change

@vszakats

vszakats commented Oct 12, 2026 •

Copy link
Copy Markdown
Member Author

I think either way is fine for logmsg in testing because the numbers aren't large, we could even wrap logmsg in win32 and scan for %z in the string and replace with %I before passing to printf if you really wanted the least amount of change

Sounds tempting, but I'm siding with keeping it simple, with the masks
const and passing them through as-is. If there arises a need to log
a large number, we can add the format macro and use it there.

For 64-bit there is CURL_FORMAT_CURL_OFF_T* which should
work here. I'll try it in a separate PR. If it works fine, it could also be
reused for large-number needs without adding new macros.

(as feared, this fails badly → 4185c6d)

One concern is how to enforce no future %z* use in this corner of
the codebase?

@jay

jay commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

One concern is how to enforce no future %z* use in this corner of
the codebase?

checksrc would need changes for this. Off the top of my head it keeps the previous line therefore lines like

logmsg("test num is 
"%zu", abc);

could be detected, but I think not

logmsg("test num "
"is "
"%zu", abc);

pretty unusual anyway. another way that is more encompassing would be check the path of the filename and check the DIR name passed as option for all c files for the path "tests" then if it's one of those files check the line for %zu and ban

@vszakats

Copy link
Copy Markdown
Member Author

Added an off-by-default checksrc rule for this, and enabled it for this directory only.

vszakats added a commit that referenced this pull request Oct 14, 2026
To catch the use of `%zd`/`%zu` masks in code that uses the CRT printfs.
This is currently in docs/example, and upcoming in tests/server in a
separate patch. These masks pass compilation in all supported compiler,
but, with the CRT of VS2013 and earlier, they result in a runtime crash.

There was existing use of these masks in examples.

Also:
- drop a stale documentation line.
  Follow-up to c445b74 #15835
- test1185: replace literal `1185` with `%TESTNUMBER`.

Cherry-picked from #23378

Closes #23383
@vszakats vszakats closed this in e9af987 Oct 14, 2026
@vszakats
vszakats deleted the servers-vs2013 branch October 14, 2026 11:00
vszakats added a commit that referenced this pull request Oct 18, 2026
- in jobs building tests, also run them.
- to maintain CI cycle times, only run unit tests by default, and run
  all (supported) tests in just one job, carefully selected to be the
  one running them the fastest.
  Per job, it takes ~15 seconds to run ~80 unit tests.
  It takes 5 minutes to run all (~1600) tests. Total job time 5.5-6
  minutes.
  If the full test run turns out to be annoying or grow slow, we disable
  or limit it to a subset of tests.
- run tests with `-j10` parallelism. It results in the fastest runs,
  based on tests.
- to avoid the MSBuild test breaker heuristics, and to improve
  performance, run tests by directly invoking `runtests.pl` (not via
  CMake -> MSBuild -> `runtests.pl`).
  It saves 10-40 seconds per full test run.
- when running directly via `runtests.pl`, exclude test 1119 and 1167.
  It's not compatible with Visual Studio generator builds.
- run the artifact upload in parallel with running tests.

Running Windows tests in multiple environments makes it more likely they
can run on local machines, too, also making them easier to debug.
AppVeyor also supports remote access via RDP, which may help debugging
notorious Windows issues live, with some luck of reproducing it in a run
with RDP access explicitly enabled beforehand.

Fixes/improvements via this PR, merged separately:

dc99e12 #23467 processhelp.pm: improve task info in trace output (Windows)
70f3f85 #23471 test1488: drop unused C preprocessor logic
af9d2dd #23336 cmake: fix preconditions for option `CURL_STATIC_CRT=ON`
adf8b78 #23428 setopt: fix setting `CURLWS_NOAUTOPONG` with compilers lacking C99 bool type
780405b #23416 tests: add `--dump-module-paths` debug option (Windows)
bc22977 #23400 msvc: replace debug CRT GUI popups with stderr output
87a1dc7 #23396 appveyor: minor improvements
67f3510 #23381 runtests: add `-S` option to show success logs
e9af987 #23378 tests/server: fix crashing with VS2013 and earlier
8cdee8a #23377 lib557: exclude three floating point test cases for VS2013 and earlier
1aac64a #23375 test1119, 1167: disable MSYS2 argument conversion narrowly
49f003f #23337 unit1664: add workaround for VS2019 16.3 - VS2022 17.4 x64 miscompile
b8f71d6 #23345 test428: skip when running on older MSYS2 versions
2f3f99d #23339 test1119, 1167: disable MSYS2 argument conversion
098d3a0 #23332 runtests: unset `CURL_MEMDEBUG` for curl requests made to the CI API
d3e7caf #23335 GHA/windows: drop unused `-ac` runtests options
2874cc6 #23317 mqttd: work around bogus VS2019 32-bit compiler warning
e8adc72 #23315 schannel: fix guard for old MSVC workaround

Follow-up to 41198e0 #20390

Closes #23306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants