From: Daniel Stenberg Date: Tue, 30 Dec 2025 23:13:24 +0000 (+0100) Subject: tool_paramhlp: remove a malloc+free from proto2num() X-Git-Tag: curl-8_18_0~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c278cd586ab648fe14c6c6389b77b7f19d9e915;p=thirdparty%2Fcurl.git tool_paramhlp: remove a malloc+free from proto2num() Closes #20120 --- diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 43315d5f73..3f8213835a 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -396,21 +396,23 @@ static void protoset_clear(const char **protoset, const char *proto) * data. */ -#define MAX_PROTOSTRING (64 * 11) /* Room for 64 10-chars proto names. */ +#define MAX_PROTOS 34 +#define MAX_PROTOSTRING (MAX_PROTOS * 11) /* Room for MAX_PROTOS number of + 10-chars proto names. */ ParameterError proto2num(const char * const *val, char **ostr, const char *str) { - const char **protoset; struct dynbuf obuf; size_t proto; CURLcode result = CURLE_OK; + const char *protoset[MAX_PROTOS + 1]; - curlx_dyn_init(&obuf, MAX_PROTOSTRING); - - protoset = curlx_malloc((proto_count + 1) * sizeof(*protoset)); - if(!protoset) + DEBUGASSERT(proto_count <= MAX_PROTOS); + if(proto_count > MAX_PROTOS) /* if case of surprises */ return PARAM_NO_MEM; + curlx_dyn_init(&obuf, MAX_PROTOSTRING); + /* Preset protocol set with default values. */ protoset[0] = NULL; for(; *val; val++) { @@ -505,7 +507,6 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str) for(proto = 0; protoset[proto] && !result; proto++) result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "", protoset[proto]); - curlx_free((char *)protoset); if(result) return PARAM_NO_MEM; if(!curlx_dyn_len(&obuf)) {