Mailing List Archive

[master] d9928c3bc http2_hpack: Remove one level of nesting
commit d9928c3bc3dd5a9be3e36363ce16e64db536f00e
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Wed Mar 27 16:28:18 2024 +0100

http2_hpack: Remove one level of nesting

Better diff with the --ignore-all-space option.

diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index a134c379a..c2013c1f2 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -169,69 +169,64 @@ h2h_addhdr(struct http *hp, struct h2h_decode *d)
return (H2SE_ENHANCE_YOUR_CALM);
}

- if (*nm.b == ':') {
- /* Match H/2 pseudo headers */
- /* XXX: Should probably have some include tbl for
- pseudo-headers */
- if (!Tstrcmp(nm, ":method")) {
- hdr.b = val.b;
- n = HTTP_HDR_METHOD;
- disallow_empty = 1;
-
- /* Check HTTP token */
- for (p = hdr.b; p < hdr.e; p++) {
- if (!vct_istchar(*p))
- return (H2SE_PROTOCOL_ERROR);
- }
- } else if (!Tstrcmp(nm, ":path")) {
- hdr.b = val.b;
- n = HTTP_HDR_URL;
- disallow_empty = 1;
-
- // rfc9113,l,2693,2705
- if (Tlen(val) > 0 && *val.b != '/' &&
- Tstrcmp(val, "*")) {
- VSLb(hp->vsl, SLT_BogoHeader,
- "Illegal :path pseudo-header %.*s",
- (int)Tlen(val), val.b);
+ /* Match H/2 pseudo headers */
+ /* XXX: Should probably have some include tbl for pseudo-headers */
+ if (!Tstrcmp(nm, ":method")) {
+ hdr.b = val.b;
+ n = HTTP_HDR_METHOD;
+ disallow_empty = 1;
+
+ /* Check HTTP token */
+ for (p = hdr.b; p < hdr.e; p++) {
+ if (!vct_istchar(*p))
return (H2SE_PROTOCOL_ERROR);
- }
+ }
+ } else if (!Tstrcmp(nm, ":path")) {
+ hdr.b = val.b;
+ n = HTTP_HDR_URL;
+ disallow_empty = 1;

- /* Path cannot contain LWS or CTL */
- for (p = hdr.b; p < hdr.e; p++) {
- if (vct_islws(*p) || vct_isctl(*p))
- return (H2SE_PROTOCOL_ERROR);
- }
- } else if (!Tstrcmp(nm, ":scheme")) {
- /* XXX: What to do about this one? (typically
- "http" or "https"). For now set it as a normal
- header, stripping the first ':'. */
- hdr.b++;
- has_dup = d->has_scheme;
- d->has_scheme = 1;
- disallow_empty = 1;
-
- /* Check HTTP token */
- for (p = val.b; p < val.e; p++) {
- if (!vct_istchar(*p))
- return (H2SE_PROTOCOL_ERROR);
- }
- } else if (!Tstrcmp(nm, ":authority")) {
- /* NB: we inject "host" in place of "rity" for
- * the ":authority" pseudo-header.
- */
- memcpy(d->out + 6, "host", 4);
- hdr.b += 6;
- nm = Tstr(":authority"); /* preserve original */
- has_dup = d->has_authority;
- d->has_authority = 1;
- } else {
- /* Unknown pseudo-header */
+ // rfc9113,l,2693,2705
+ if (Tlen(val) > 0 && val.b[0] != '/' && Tstrcmp(val, "*")) {
VSLb(hp->vsl, SLT_BogoHeader,
- "Unknown pseudo-header: %.*s",
- vmin_t(int, Tlen(hdr), 20), hdr.b);
- return (H2SE_PROTOCOL_ERROR); // rfc7540,l,2990,2992
+ "Illegal :path pseudo-header %.*s",
+ (int)Tlen(val), val.b);
+ return (H2SE_PROTOCOL_ERROR);
}
+
+ /* Path cannot contain LWS or CTL */
+ for (p = hdr.b; p < hdr.e; p++) {
+ if (vct_islws(*p) || vct_isctl(*p))
+ return (H2SE_PROTOCOL_ERROR);
+ }
+ } else if (!Tstrcmp(nm, ":scheme")) {
+ /* XXX: What to do about this one? (typically
+ "http" or "https"). For now set it as a normal
+ header, stripping the first ':'. */
+ hdr.b++;
+ has_dup = d->has_scheme;
+ d->has_scheme = 1;
+ disallow_empty = 1;
+
+ /* Check HTTP token */
+ for (p = val.b; p < val.e; p++) {
+ if (!vct_istchar(*p))
+ return (H2SE_PROTOCOL_ERROR);
+ }
+ } else if (!Tstrcmp(nm, ":authority")) {
+ /* NB: we inject "host" in place of "rity" for
+ * the ":authority" pseudo-header.
+ */
+ memcpy(d->out + 6, "host", 4);
+ hdr.b += 6;
+ nm = Tstr(":authority"); /* preserve original */
+ has_dup = d->has_authority;
+ d->has_authority = 1;
+ } else if (nm.b[0] == ':') {
+ VSLb(hp->vsl, SLT_BogoHeader,
+ "Unknown pseudo-header: %.*s",
+ vmin_t(int, Tlen(hdr), 20), hdr.b);
+ return (H2SE_PROTOCOL_ERROR); // rfc7540,l,2990,2992
}

if (disallow_empty && Tlen(val) == 0) {
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit