From 0c475b5df746f417609a5b25ed6ed59a6db63f2f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 22 Mar 2026 23:53:35 +0100 Subject: [PATCH] urlapi: remove redundant condition in dedotdotify Bonus: remove two variables, clear up some comments. Poined out by CodeSonar Closes #21065 --- lib/urlapi.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/urlapi.c b/lib/urlapi.c index a300477a1b..a882473141 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -731,31 +731,25 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) curlx_dyn_init(&out, clen + 1); - /* A. If the input buffer begins with a prefix of "../" or "./", then - remove that prefix from the input buffer; otherwise, */ + /* if the input buffer begins with a prefix of "../" or "./", then remove + that prefix from the input buffer; otherwise, */ if(is_dot(&dinput, &dlen)) { - const char *p = dinput; - size_t blen = dlen; - - if(!clen) - /* . [end] */ - goto end; - else if(ISSLASH(*p)) { + if(ISSLASH(*dinput)) { /* one dot followed by a slash */ - input = p + 1; + input = dinput + 1; clen = dlen - 1; } - /* D. if the input buffer consists only of "." or "..", then remove - that from the input buffer; otherwise, */ - else if(is_dot(&p, &blen)) { - if(!blen) + /* if the input buffer consists only of "." or "..", then remove + that from the input buffer; otherwise, */ + else if(is_dot(&dinput, &dlen)) { + if(!dlen) /* .. [end] */ goto end; - else if(ISSLASH(*p)) { + else if(ISSLASH(*dinput)) { /* ../ */ - input = p + 1; - clen = blen - 1; + input = dinput + 1; + clen = dlen - 1; } } } @@ -764,9 +758,9 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) if(ISSLASH(*input)) { const char *p = &input[1]; size_t blen = clen - 1; - /* B. if the input buffer begins with a prefix of "/./" or "/.", where - "." is a complete path segment, then replace that prefix with "/" in - the input buffer; otherwise, */ + /* if the input buffer begins with a prefix of "/./" or "/.", where "." + is a complete path segment, then replace that prefix with "/" in the + input buffer; otherwise, */ if(is_dot(&p, &blen)) { if(!blen) { /* /. */ result = curlx_dyn_addn(&out, "/", 1); @@ -778,10 +772,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) continue; } - /* C. if the input buffer begins with a prefix of "/../" or "/..", - where ".." is a complete path segment, then replace that prefix - with "/" in the input buffer and remove the last segment and its - preceding "/" (if any) from the output buffer; otherwise, */ + /* if the input buffer begins with a prefix of "/../" or "/..", where + ".." is a complete path segment, then replace that prefix with "/" + in the input buffer and remove the last segment and its preceding + "/" (if any) from the output buffer; otherwise, */ else if(is_dot(&p, &blen) && (ISSLASH(*p) || !blen)) { /* remove the last segment from the output buffer */ size_t len = curlx_dyn_len(&out); @@ -804,10 +798,10 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) } } - /* E. move the first path segment in the input buffer to the end of - the output buffer, including the initial "/" character (if any) and - any subsequent characters up to, but not including, the next "/" - character or the end of the input buffer. */ + /* move the first path segment in the input buffer to the end of the + output buffer, including the initial "/" character (if any) and any + subsequent characters up to, but not including, the next "/" character + or the end of the input buffer. */ result = curlx_dyn_addn(&out, input, 1); input++;