]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: Reapply ist.cocci with `--include-headers-for-types --recursive-includes`
authorTim Duesterhus <tim@bastelstu.be>
Tue, 15 Mar 2022 12:11:06 +0000 (13:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 21 Mar 2022 07:30:47 +0000 (08:30 +0100)
Previous uses of `ist.cocci` did not add `--include-headers-for-types` and
`--recursive-includes` preventing Coccinelle seeing `struct ist` members of
other structs.

Reapply the patch with proper flags to further clean up the use of the ist API.

The command used was:

    spatch -sp_file dev/coccinelle/ist.cocci -in_place --include-headers --include-headers-for-types --recursive-includes --dir src/

12 files changed:
src/cache.c
src/fcgi.c
src/flt_http_comp.c
src/h1.c
src/h2.c
src/http_fetch.c
src/http_htx.c
src/log.c
src/mux_fcgi.c
src/mux_h1.c
src/sink.c
src/tcpcheck.c

index 60f9a0ed7431a2d48f255b2d09793de34582f472..0f90af9843cf1b05c470726bcd786c731f9299cd 100644 (file)
@@ -626,7 +626,7 @@ cache_store_http_payload(struct stream *s, struct filter *filter, struct http_ms
 
                                info = (type << 28) + v.len;
                                chunk_memcat(&trash, (char *)&info, sizeof(info));
-                               chunk_memcat(&trash, v.ptr, v.len);
+                               chunk_istcat(&trash, v);
                                to_forward += v.len;
                                len -= v.len;
                                break;
index 1c2543def6b04436495a44f285f070b45ae66714..dcf2db219656d51f7f66717c4ce7e1d2232a500f 100644 (file)
@@ -197,10 +197,8 @@ size_t fcgi_decode_param(const struct buffer *in, size_t o, struct fcgi_param *p
        if (data < nlen + vlen)
                return 0;
 
-       p->n.ptr = b_peek(in, o);
-       p->n.len = nlen;
-       p->v.ptr = b_peek(in, o+nlen);
-       p->v.len = vlen;
+       p->n = ist2(b_peek(in, o), nlen);
+       p->v = ist2(b_peek(in, o + nlen), vlen);
        len += nlen + vlen;
 
        return len;
@@ -254,10 +252,8 @@ size_t fcgi_aligned_decode_param(const struct buffer *in, size_t o, struct fcgi_
        if (data < nlen + vlen)
                return 0;
 
-       p->n.ptr = in->area + o;
-       p->n.len = nlen;
-       p->v.ptr = in->area + o + nlen;
-       p->v.len = vlen;
+       p->n = ist2(in->area + o, nlen);
+       p->v = ist2(in->area + o + nlen, vlen);
        len += nlen + vlen;
 
        return len;
index f2b210a6770d5fe8034cc8d6f5c3958e8d9d0e56..08f684e511fda5d982f96c08bcf09d70ac7a810f 100644 (file)
@@ -400,26 +400,26 @@ select_compression_request_header(struct comp_state *st, struct stream *s, struc
 
                        qval = ctx.value.ptr + toklen;
                        while (1) {
-                               while (qval < ctx.value.ptr + ctx.value.len && HTTP_IS_LWS(*qval))
+                               while (qval < istend(ctx.value) && HTTP_IS_LWS(*qval))
                                        qval++;
 
-                               if (qval >= ctx.value.ptr + ctx.value.len || *qval != ';') {
+                               if (qval >= istend(ctx.value) || *qval != ';') {
                                        qval = NULL;
                                        break;
                                }
                                qval++;
 
-                               while (qval < ctx.value.ptr + ctx.value.len && HTTP_IS_LWS(*qval))
+                               while (qval < istend(ctx.value) && HTTP_IS_LWS(*qval))
                                        qval++;
 
-                               if (qval >= ctx.value.ptr + ctx.value.len) {
+                               if (qval >= istend(ctx.value)) {
                                        qval = NULL;
                                        break;
                                }
-                               if (strncmp(qval, "q=", MIN(ctx.value.ptr + ctx.value.len - qval, 2)) == 0)
+                               if (strncmp(qval, "q=", MIN(istend(ctx.value) - qval, 2)) == 0)
                                        break;
 
-                               while (qval < ctx.value.ptr + ctx.value.len && *qval != ';')
+                               while (qval < istend(ctx.value) && *qval != ';')
                                        qval++;
                        }
 
index dd208f3235b514442e2d9575e5b2905521685bbd..bf546b9d7fee6fb412f8c7244b92e6039e2dbf2e 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -428,8 +428,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                http_msg_req09_uri_e:
                        sl.rq.u.len = ptr - sl.rq.u.ptr;
                http_msg_req09_ver:
-                       sl.rq.v.ptr = ptr;
-                       sl.rq.v.len = 0;
+                       sl.rq.v = ist2(ptr, 0);
                        goto http_msg_rqline_eol;
                }
                state = H1_MSG_RQMETH;
@@ -659,8 +658,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                sl.st.c.len = ptr - sl.st.c.ptr;
 
        http_msg_rsp_reason:
-               sl.st.r.ptr = ptr;
-               sl.st.r.len = 0;
+               sl.st.r = ist2(ptr, 0);
                goto http_msg_rpline_eol;
 
        case H1_MSG_RPCODE_SP:
index 49a1252e900aeacaf5078741761bf57aa2dbc72f..5c3a6aeaf8ecba1911c0448072ab6054b0e707ad 100644 (file)
--- a/src/h2.c
+++ b/src/h2.c
@@ -402,7 +402,7 @@ int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms
        lck = ck = -1; // no cookie for now
        fields = 0;
        for (idx = 0; list[idx].n.len != 0; idx++) {
-               if (!list[idx].n.ptr) {
+               if (!isttest(list[idx].n)) {
                        /* this is an indexed pseudo-header */
                        phdr = list[idx].n.len;
                }
@@ -721,7 +721,7 @@ int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m
 
        fields = 0;
        for (idx = 0; list[idx].n.len != 0; idx++) {
-               if (!list[idx].n.ptr) {
+               if (!isttest(list[idx].n)) {
                        /* this is an indexed pseudo-header */
                        phdr = list[idx].n.len;
                }
@@ -873,7 +873,7 @@ int h2_make_htx_trailers(struct http_hdr *list, struct htx *htx)
        int i;
 
        for (idx = 0; list[idx].n.len != 0; idx++) {
-               if (!list[idx].n.ptr) {
+               if (!isttest(list[idx].n)) {
                        /* This is an indexed pseudo-header (RFC7540#8.1.2.1) */
                        goto fail;
                }
index 22919d3549ae2c9009438daa158e44be81aba44c..2ee507b65f1cb63c342b72274402eb6aecabf167 100644 (file)
@@ -1099,7 +1099,7 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char
 
        /* OK we have the header value in ctx.value */
        temp = get_trash_chunk();
-       chunk_memcat(temp, ctx.value.ptr, ctx.value.len);
+       chunk_istcat(temp, ctx.value);
 
        /* now retrieve the path */
        sl = http_get_stline(htx);
index 3535fa71330cdd56896c94a5b3d7b85bafe125a7..d9584abaeaca454815334fd3351e87f8eaf6406a 100644 (file)
@@ -139,7 +139,7 @@ static int __http_find_header(const struct htx *htx, const void *pattern, struct
                if (flags & HTTP_FIND_FL_FULL)
                        goto next_blk;
                v = htx_get_blk_value(htx, blk);
-               p = ctx->value.ptr + ctx->value.len + ctx->lws_after;
+               p = istend(ctx->value) + ctx->lws_after;
                v.len -= (p - v.ptr);
                v.ptr  = p;
                if (!v.len)
@@ -574,8 +574,7 @@ int http_replace_header_value(struct htx *htx, struct http_hdr_ctx *ctx, const s
        }
 
        ctx->blk = blk;
-       ctx->value.ptr = v.ptr + off;
-       ctx->value.len = data.len;
+       ctx->value = ist2(v.ptr + off, data.len);
        ctx->lws_before = ctx->lws_after = 0;
 
        return 1;
@@ -674,8 +673,7 @@ int http_remove_header(struct htx *htx, struct http_hdr_ctx *ctx)
        htx_change_blk_value_len(htx, blk, v.len-len);
 
        /* Finally update the ctx */
-       ctx->value.ptr = start;
-       ctx->value.len = 0;
+       ctx->value = ist2(start, 0);
        ctx->lws_before = ctx->lws_after = 0;
 
        return 1;
@@ -1057,7 +1055,7 @@ static int http_htx_init(void)
                        continue;
                }
 
-               raw = ist2(http_err_msgs[rc], strlen(http_err_msgs[rc]));
+               raw = ist(http_err_msgs[rc]);
                if (!http_str_to_htx(&chk, raw, &errmsg)) {
                        ha_alert("Internal error: invalid default message for HTTP return code %d: %s.\n",
                                 http_err_codes[rc], errmsg);
index 9952aaa15609d7c8820f9a298191981bbb1d7d05..744cb034f3d89fa89edf224554a26ddd112c06cb 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1803,7 +1803,7 @@ void __send_log(struct list *logsrvs, struct buffer *tagb, int level,
 
        if (!metadata[LOG_META_HOST].len) {
                if (global.log_send_hostname)
-                       metadata[LOG_META_HOST] = ist2(global.log_send_hostname, strlen(global.log_send_hostname));
+                       metadata[LOG_META_HOST] = ist(global.log_send_hostname);
        }
 
        if (!tagb || !tagb->area)
index ef264edaef329a29e4ed61638d48efa42f943d71..8a7fc5acb615bff88f2cdc2887609647d38498cb 100644 (file)
@@ -1417,7 +1417,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
 
                        params->scriptname = ist2(b_tail(params->p), len+fconn->app->index.len);
                        chunk_istcat(params->p, sn);
-                       chunk_memcat(params->p, fconn->app->index.ptr, fconn->app->index.len);
+                       chunk_istcat(params->p, fconn->app->index);
                }
        }
 
@@ -1494,16 +1494,16 @@ static int fcgi_encode_default_param(struct fcgi_conn *fconn, struct fcgi_strm *
                        goto encode;
                case FCGI_SP_SCRIPT_FILE:
                        p.n = ist("SCRIPT_FILENAME");
-                       chunk_memcat(&trash, params->docroot.ptr, params->docroot.len);
-                       chunk_memcat(&trash, params->scriptname.ptr, params->scriptname.len);
+                       chunk_istcat(&trash, params->docroot);
+                       chunk_istcat(&trash, params->scriptname);
                        p.v = ist2(b_head(&trash), b_data(&trash));
                        goto encode;
                case FCGI_SP_PATH_TRANS:
                        if (!istlen(params->pathinfo))
                                goto skip;
                        p.n = ist("PATH_TRANSLATED");
-                       chunk_memcat(&trash, params->docroot.ptr, params->docroot.len);
-                       chunk_memcat(&trash, params->pathinfo.ptr, params->pathinfo.len);
+                       chunk_istcat(&trash, params->docroot);
+                       chunk_istcat(&trash, params->pathinfo);
                        p.v = ist2(b_head(&trash), b_data(&trash));
                        goto encode;
                case FCGI_SP_CONT_LEN:
index 3e2ea2655ea0e7193be6560802ae1c9f74276a29..886caaaa7a369b5a17983315ae717412ee2a1894 100644 (file)
@@ -2595,7 +2595,7 @@ static int h1_send_error(struct h1c *h1c)
                TRACE_STATE("waiting for h1c obuf allocation", H1_EV_H1C_ERR|H1_EV_H1C_BLK, h1c->conn);
                goto out;
        }
-       ret = b_istput(&h1c->obuf, ist2(http_err_msgs[rc], strlen(http_err_msgs[rc])));
+       ret = b_istput(&h1c->obuf, ist(http_err_msgs[rc]));
        if (unlikely(ret <= 0)) {
                if (!ret) {
                        h1c->flags |= (H1C_F_OUT_FULL|H1C_F_ERR_PENDING);
index dd6f6b04a0d8bc7b14bca5a1e01ae738d498aa52..eec8570f1cd0d38455940656666181e85219ab3c 100644 (file)
@@ -205,7 +205,7 @@ int sink_announce_dropped(struct sink *sink, int facility)
 
                if (!metadata[LOG_META_HOST].len) {
                        if (global.log_send_hostname)
-                               metadata[LOG_META_HOST] = ist2(global.log_send_hostname, strlen(global.log_send_hostname));
+                               metadata[LOG_META_HOST] = ist(global.log_send_hostname);
                }
 
                if (!metadata[LOG_META_TAG].len)
index ba9321eb18e7f2897f977994e277f799e8c76310..1926311f7fa213201c8073e1dcf0947194078e7f 100644 (file)
@@ -4992,7 +4992,7 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s
                        }
                        LIST_INIT(&hdr->value);
                        hdr->name = istdup(tmp_hdrs[i].n);
-                       if (!hdr->name.ptr) {
+                       if (!isttest(hdr->name)) {
                                memprintf(errmsg, "out of memory");
                                goto error;
                        }