TESTrun: Add reject tests for uncovered savefile-parser diagnostics - #1704
anthonyadame wants to merge 1 commit into
Conversation
| { | ||
| name => 'pcap_truncated_hdr_4', | ||
| savefile => 'pcap-truncated-hdr-4.pcap', | ||
| errstr => 'Failed opening: truncated dump file; tried to read 24 file header bytes, only got 0', |
There was a problem hiding this comment.
For .pcap files it seems the current error messages are 4 bytes short of how much has actually been read; this problem has not been introduced by this change, but it should be noted that the 23-byte file below indeed looks a boundary case, but the 4-byte file does not. Should this be an empty file instead?
|
Thank you for preparing these changes. It seems to me, the new tests would be easier to maintain if each test description was a Perl comment next to the test definition rather than a table in the pull request. The code path could be useful as well, similar to how it is noted for some of the existing tests: |
Adds 16 malformed savefiles plus their expected diagnostics to the "Savefile-based reject tests follow." section, covering error paths whose diagnostic strings are not asserted by any current test: an empty file and a truncated classic file header, and in the pcapng reader a missing IDB, a packet block before any IDB, block length < 12, block length not a multiple of 4, SHB length out of range, a truncated SHB read, and the if_tsresol / if_tsoffset / opt_endofopt option-validation paths. Each test carries a comment noting the code path it exercises. Each errstr is taken verbatim from the library output for that input. No source or build changes; tests/ is picked up by TEST_DIST automatically.
e4b355f to
ff01d9d
Compare
|
Thanks — both good points, done in the update. Each test now carries a comment above it noting the code path it exercises, in the same style as On the 4-byte file: you're right, and it turned out to be more than a cosmetic fix. The 4-byte I've left the "4 bytes short" message itself alone — as you say it predates this change, so it Full set still passes via |
What
Adds 16 test vectors to the
# Savefile-based reject tests follow.section oftestprogs/TESTrun, covering savefile-parser error paths whose diagnostics are not asserted byany current test — mostly in the pcapng block/option parser.
Each vector is a small (a few dozen bytes) malformed savefile plus the exact diagnostic
pcap_open_offline()must produce for it.BT_SHB_INSANE_MAXif_tsresolbad option lengthif_tsresolopt_endofoptwith non-zero lengthif_tsresoldecimal resolution too highif_tsresolbinary resolution too highif_tsoffsetbad option lengthif_tsoffset16 files, 720 bytes total. No source or build-file changes —
TEST_DISTalready picks uptests/viagit ls-files.Why
None of these error paths currently has a test asserting its diagnostic (verified against this
tree: none of the corresponding messages appears anywhere under
testprogs/). Thefuzz_pcaptarget exercises the open path, but it discards the error text and only checks that malformed
input doesn't crash the parser — so a change to any of these diagnostics is not caught by
anything today. These vectors pin the current messages, in the same form as the six existing
savefile reject tests, so future changes to
sf-pcap.c/sf-pcapng.ccan't silently alterthem.
How the expected strings were produced
The
errstrvalues are not hand-written — each is captured verbatim from the output of alibpcap build of this tree, so the assertion matches exactly what the library emits. The
generator was first validated against the six existing savefile reject tests and reproduced
all six declared
errstrvalues.Testing
perl testprogs/TESTrun --one reject_<name>(each0 tests failed / 1 tests passed).perl -c testprogs/TESTrunis clean.Verified with a CMake Release build on Ubuntu 24.04 / gcc 13.