eBPF-based security platform
bpm: ignore a registry header line that holds a NUL
Daniel Borkmannc7c601d37dd8
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex b1da8ff7..6b267182 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -241,10 +241,10 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.- Header lines up to 26 bytes, NULs included, with the line's copyand the challenge's field set to 24 and 4 bytes for their 4096and 2048- - The whole line taken, and one too long for the copy read not at- all; values terminated, without a leading blank, a location- without CR or LF; a challenge that fits kept whole, a longer one- dropped rather than cut+ - The whole line taken, and one too long for the copy or holding a+ NUL read not at all; values terminated, without a leading blank,+ a location without CR or LF; a challenge that fits kept whole, a+ longer one dropped rather than cut* - ``bpm-oci-buffer``- ``bpm_buffer_append()``- A buffer of 0, 3, 8, 12 and 15 bytes holding any shorter body,diff --git a/testing/proofs/cbmc/bpm-oci-header.c b/testing/proofs/cbmc/bpm-oci-header.cindex e92bdedf..43419034 100644--- a/testing/proofs/cbmc/bpm-oci-header.c+++ b/testing/proofs/cbmc/bpm-oci-header.c@@ -4,9 +4,10 @@** bpm_header() of util/bpm_oci.c, libcurl's header callback, for every* header line of up to LINE_MAX bytes, NULs included: it takes the whole- * line, reads none longer than its copy, and the challenge and location- * it keeps are terminated inside their fields, the location without a- * line break, a challenge longer than its field dropped rather than cut.+ * line, reads none longer than its copy nor one holding a NUL, and the+ * challenge and location it keeps are terminated inside their fields, the+ * location without a line break, a challenge longer than its field+ * dropped rather than cut.* The copy and the challenge's field are of 24 and 4 bytes here, for 4096* and 2048, which are past what CBMC can hold: the checks against them* are the same expressions.@@ -91,6 +92,11 @@ void harness(void)"a line longer than the copy read not at all");return;}+ if (memchr(line, '\0', n)) {+ __CPROVER_assert(!r.www_auth[0] && !r.location[0],+ "a line holding a NUL read not at all");+ return;+ }__CPROVER_assert(short_string(r.www_auth, sizeof(r.www_auth)) &&short_string(r.location, sizeof(r.location)),"every value terminated inside its field");diff --git a/util/bpm_oci.c b/util/bpm_oci.cindex f4ccd038..c0cd4569 100644--- a/util/bpm_oci.c+++ b/util/bpm_oci.c@@ -161,10 +161,8 @@ static size_t bpm_header(void *ptr, size_t size, size_t nmemb, void *ud)size_t n = size * nmemb;char *v;- if (n >= sizeof(line))+ if (span_to_str(line, sizeof(line), ptr, n))return n;- memcpy(line, ptr, n);- line[n] = '\0';v = line;if (str_skip_prefix_nocase(&v, "WWW-Authenticate:")) {while (isspace((__u8)*v))