From c35e2cb29f3a20fa6fb330027c77216e0bc6297f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Jun 2026 10:43:53 +0200 Subject: [PATCH] setopt: cleanup the length check for COPYPOSTFIELDS handling Make it more straight-forward Closes #22127 --- lib/setopt.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/setopt.c b/lib/setopt.c index 0c0d47a680..df054469d4 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -1814,14 +1814,12 @@ static CURLcode setopt_cptr_proxy(struct Curl_easy *data, CURLoption option, static CURLcode setopt_copypostfields(const char *ptr, struct UserDefined *s) { CURLcode result = CURLE_OK; + if(s->postfieldsize < -1) + return CURLE_BAD_FUNCTION_ARGUMENT; if(!ptr || s->postfieldsize == -1) result = Curl_setstropt(&s->str[STRING_COPYPOSTFIELDS], ptr); else { - size_t pflen; - - if(s->postfieldsize < 0) - return CURLE_BAD_FUNCTION_ARGUMENT; - pflen = curlx_sotouz_range(s->postfieldsize, 0, SIZE_MAX); + size_t pflen = curlx_sotouz_range(s->postfieldsize, 0, SIZE_MAX); if(pflen == SIZE_MAX) return CURLE_OUT_OF_MEMORY; else {