Skip to content

eBPF-based security platform

proofs: reach the copy of an unknown option's name in options-long

Daniel Borkmannf0d61619692a
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 4a4d5910..d10c5e7d 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -1036,6 +1036,11 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
value lies in an argument; a flag has no value; a value is there
and not empty unless the option allows it; no option comes back
twice unless it repeats; a number lies in its bounds
+ * - ``options-long``
+ - ``opt_unknown()`` through ``opt_next()``
+ - One unknown option of 64 to 66 bytes, around the 65 its copy
+ holds
+ - Refused, and a name suggested for it only when it fits the copy
* - ``conditions-verdict``
- ``status_verdict()``, ``status_reason()``
- Every input; reasons into 1, 8, 32 and 160 bytes
diff --git a/testing/proofs/cbmc/options-long.c b/testing/proofs/cbmc/options-long.c
new file mode 100644
index 00000000..671acadd
--- /dev/null
+++ b/testing/proofs/cbmc/options-long.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * opt_next() of util/options.c on one unknown option of LEN bytes, around
+ * the 65 that opt_unknown() copies to suggest a name for it: refused,
+ * with a suggestion only for one that fits the copy.
+ */
+
+#define OPTIONS_LONG 1
+#include "options-next.c"
diff --git a/testing/proofs/cbmc/options-next.c b/testing/proofs/cbmc/options-next.c
index 2f1f180c..4fdf97c8 100644
--- a/testing/proofs/cbmc/options-next.c
+++ b/testing/proofs/cbmc/options-next.c
@@ -8,6 +8,8 @@
* one argument, so a run ends, what it hands back lies in an argument, a
* flag has no value, a value is there and not empty unless the option
* allows it, and no option comes back twice unless it repeats.
+ * options-long.c includes this file for an unknown option too long to
+ * suggest one for.
*/
#include <errno.h>
@@ -70,6 +72,21 @@ void help_suggest(const char *bad, const char *const *names, size_t n_names)
__CPROVER_assert(strlen(bad) <= SIMILAR_MAX_LEN, "the word fits");
}
+#if defined(OPTIONS_LONG)
+/* One unknown option of LEN bytes, "--" and then a constant byte. */
+void harness(void)
+{
+ char text[LEN + 1];
+ const char *arg = text;
+ struct opt_parser p;
+
+ memcpy(text, "--", 2);
+ memset(text + 2, 'x', LEN - 2);
+ text[LEN] = '\0';
+ OPT_INIT(&p, "proof", specs, NULL, 1, &arg, 0);
+ __CPROVER_assert(opt_next(&p) == OPT_USAGE, "an unknown option refused");
+}
+#else
static const char *argv[ARGS_MAX];
static size_t lens[ARGS_MAX];
@@ -151,3 +168,4 @@ void harness(void)
if (opt == P_N && !opt_u64(&p, 1, 512, &n))
__CPROVER_assert(n >= 1 && n <= 512, "a number in bounds");
}
+#endif
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 1e734d6e..032bef3e 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -100,6 +100,7 @@ similar-distance --max-field-sensitivity-array-size 65 --unwind 8 --unwindset me
similar-suggest --object-bits 10 --max-field-sensitivity-array-size 65 --unwind 8 --unwindset memcpy.0:14 LEN=0-8,18-26
similar-resolve --object-bits 10 --unwind 8
options-next --object-bits 12 --unwind 8 LEN=0-6
+options-long --object-bits 12 --unwind 8 --unwindset strcspn.1:67,strlen.0:67 LEN=64-66
config-evidence-event --unwind 1 --unwindset harness.0:33,same_event.0:33,hex_digits.0:65,room_for.0:10,on_event.0:4,hex_decode.0:33,strlen.0:66 LEN=0,1,15,16,128,4095,4096
config-evidence-parse --unwind 1 --unwindset config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,any_document.0:4,whole.0:4,in_order.0:4,hex_digits.0:65,spells.0:33,blank.0:33,check_as_said.0:4,check_as_said.1:33 --memory-leak-check --slice-formula LEN=0-2
config-evidence-roundtrip --unwind 1 --unwindset config_evidence_emit.0:4,hex_encode.0:33,config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,json_kv_string.0:66,sequence_overflows.0:4,replays.0:4,same.0:33,blank.0:33,check_read_back.0:4 --memory-leak-check --slice-formula LEN=0-2