Willy, this one needs careful review. I primarily worked with dumb regex based search to find locations to change and changed them manually. I guess with Coccinelle this is easier, but I never used that and leave this up to someone experienced.
Feel free to just drop this patch if you consider it too risky. Best regards Tim Düsterhus Apply with `git am --scissors` to automatically cut the commit message. -- >8 -- This adjusts a few locations to make use of `isttest()` and `istfree()`. --- src/fcgi-app.c | 12 ++++++------ src/hlua.c | 2 +- src/hpack-dec.c | 8 ++++---- src/http_act.c | 17 ++++++++--------- src/http_ana.c | 6 +++--- src/http_fetch.c | 8 ++++---- src/http_htx.c | 4 ++-- src/mux_h1.c | 4 ++-- 8 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/fcgi-app.c b/src/fcgi-app.c index 5d2658096..8472cf58d 100644 --- a/src/fcgi-app.c +++ b/src/fcgi-app.c @@ -838,9 +838,9 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw } if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) goto out; - free(curapp->docroot.ptr); + istfree(&curapp->docroot); curapp->docroot = ist2(strdup(args[1]), strlen(args[1])); - if (!curapp->docroot.ptr) { + if (!isttest(curapp->docroot)) { ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); err_code |= ERR_ALERT | ERR_ABORT; } @@ -871,9 +871,9 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw } if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) goto out; - free(curapp->index.ptr); + istfree(&curapp->index); curapp->index = ist2(strdup(args[1]), strlen(args[1])); - if (!curapp->index.ptr) { + if (!isttest(curapp->index)) { ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); err_code |= ERR_ALERT | ERR_ABORT; } @@ -1070,8 +1070,8 @@ void fcgi_apps_deinit() struct fcgi_rule_conf *rule, *back; free(curapp->name); - free(curapp->docroot.ptr); - free(curapp->index.ptr); + istfree(&curapp->docroot); + istfree(&curapp->index); regex_free(curapp->pathinfo_re); free(curapp->conf.file); diff --git a/src/hlua.c b/src/hlua.c index d8e538b63..4043e29c2 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -3889,7 +3889,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx) lua_settable(L, -3); path = http_get_path(htx_sl_req_uri(sl)); - if (path.ptr) { + if (isttest(path)) { char *p, *q, *end; p = path.ptr; diff --git a/src/hpack-dec.c b/src/hpack-dec.c index b4d8f0d39..fa25ac475 100644 --- a/src/hpack-dec.c +++ b/src/hpack-dec.c @@ -191,7 +191,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len, } value = hpack_alloc_string(tmp, idx, hpack_idx_to_value(dht, idx)); - if (!value.ptr) { + if (!isttest(value)) { hpack_debug_printf("##ERR@%d##\n", __LINE__); ret = -HPACK_ERR_TOO_LARGE; goto leave; @@ -202,7 +202,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len, if (!name.len) { name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx)); - if (!name.ptr) { + if (!isttest(name)) { hpack_debug_printf("##ERR@%d##\n", __LINE__); ret = -HPACK_ERR_TOO_LARGE; goto leave; @@ -412,7 +412,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len, if (!name.len) { name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx)); - if (!name.ptr) { + if (!isttest(name)) { hpack_debug_printf("##ERR@%d##\n", __LINE__); ret = -HPACK_ERR_TOO_LARGE; goto leave; @@ -444,7 +444,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len, } hpack_debug_printf("\e[1;34m%s\e[0m: ", - name.ptr ? istpad(trash.area, name).ptr : h2_phdr_to_str(name.len)); + isttest(name) ? istpad(trash.area, name).ptr : h2_phdr_to_str(name.len)); hpack_debug_printf("\e[1;35m%s\e[0m [mustidx=%d, used=%d] [n=(%p,%d) v=(%p,%d)]\n", istpad(trash.area, value).ptr, must_index, diff --git a/src/http_act.c b/src/http_act.c index 9bfa7ebe4..7c16c336c 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -56,8 +56,7 @@ static void release_http_action(struct act_rule *rule) { struct logformat_node *lf, *lfb; - if (rule->arg.http.str.ptr) - free(rule->arg.http.str.ptr); + istfree(&rule->arg.http.str); if (rule->arg.http.re) regex_free(rule->arg.http.re); list_for_each_entry_safe(lf, lfb, &rule->arg.http.fmt, list) { @@ -1257,7 +1256,7 @@ static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg cur_arg++; if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { - free(rule->arg.http.str.ptr); + istfree(&rule->arg.http.str); return ACT_RET_PRS_ERR; } @@ -1351,7 +1350,7 @@ static enum act_parse_ret parse_http_replace_header(const char **args, int *orig cur_arg++; if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, err))) { - free(rule->arg.http.str.ptr); + istfree(&rule->arg.http.str); return ACT_RET_PRS_ERR; } @@ -1366,7 +1365,7 @@ static enum act_parse_ret parse_http_replace_header(const char **args, int *orig cur_arg++; if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) { - free(rule->arg.http.str.ptr); + istfree(&rule->arg.http.str); regex_free(rule->arg.http.re); return ACT_RET_PRS_ERR; } @@ -1829,7 +1828,7 @@ static void release_http_return(struct act_rule *rule) free(lf->arg); free(lf); } - free(hdr->name.ptr); + istfree(&hdr->name); free(hdr); } free(rule->arg.http_return.hdrs); @@ -2295,7 +2294,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st free(lf->arg); free(lf); } - free(hdr->name.ptr); + istfree(&hdr->name); free(hdr); } } @@ -2366,7 +2365,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st free(lf->arg); free(lf); } - free(hdr->name.ptr); + istfree(&hdr->name); free(hdr); } } @@ -2444,7 +2443,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st free(lf->arg); free(lf); } - free(hdr->name.ptr); + istfree(&hdr->name); free(hdr); } free(hdrs); diff --git a/src/http_ana.c b/src/http_ana.c index e268d4c95..a97066085 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -2503,7 +2503,7 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); /* build message using path */ - if (path.ptr) { + if (isttest(path)) { if (rule->flags & REDIRECT_FLAG_DROP_QS) { int qs = 0; while (qs < path.len) { @@ -2551,7 +2551,7 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); /* build message using path */ - if (path.ptr) { + if (isttest(path)) { if (rule->flags & REDIRECT_FLAG_DROP_QS) { int qs = 0; while (qs < path.len) { @@ -4252,7 +4252,7 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si) htx = htxbuf(&req->buf); sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); - if (!path.ptr) + if (!isttest(path)) return; if (!chunk_memcat(&trash, path.ptr, path.len)) diff --git a/src/http_fetch.c b/src/http_fetch.c index dbbb5ecfd..9113b5e49 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -987,7 +987,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char sl = http_get_stline(htx); path = iststop(http_get_path(htx_sl_req_uri(sl)), '?'); - if (!path.ptr) + if (!isttest(path)) return 0; /* OK, we got the '/' ! */ @@ -1028,7 +1028,7 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char /* now retrieve the path */ sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); - if (path.ptr) { + if (isttest(path)) { size_t len; for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) @@ -1074,7 +1074,7 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch /* now retrieve the path */ sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); - if (path.ptr) { + if (isttest(path)) { size_t len; for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++) @@ -1422,7 +1422,7 @@ static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, path.len = ptr - path.ptr; path = http_get_path(path); - if (!path.ptr) + if (!isttest(path)) return 0; smp->data.u.str.area = path.ptr; diff --git a/src/http_htx.c b/src/http_htx.c index 8157eb560..0e686956c 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -111,7 +111,7 @@ int http_find_header(const struct htx *htx, const struct ist name, if (blk) { char *p; - if (!ctx->value.ptr) + if (!isttest(ctx->value)) goto rescan_hdr; if (full) goto next_blk; @@ -309,7 +309,7 @@ int http_replace_req_path(struct htx *htx, const struct ist path) uri = htx_sl_req_uri(sl); p = http_get_path(uri); - if (!p.ptr) + if (!isttest(p)) p = uri; while (plen < p.len && *(p.ptr + plen) != '?') plen++; diff --git a/src/mux_h1.c b/src/mux_h1.c index 2e2dbf943..72606293f 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -2853,7 +2853,7 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err) entry->name.len = strlen(to); if (!entry->node.key || !entry->name.ptr) { free(entry->node.key); - free(entry->name.ptr); + istfree(&entry->name); free(entry); memprintf(err, "out of memory"); return -1; @@ -2873,7 +2873,7 @@ static void h1_hdeaders_case_adjust_deinit() ebpt_delete(node); entry = container_of(node, struct h1_hdr_entry, node); free(entry->node.key); - free(entry->name.ptr); + istfree(&entry->name); free(entry); node = next; } -- 2.25.1