]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http_aws_sigv4: simplify, avoid many gotos
authorDaniel Stenberg <daniel@haxx.se>
Fri, 23 May 2025 06:48:22 +0000 (08:48 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 23 May 2025 07:09:26 +0000 (09:09 +0200)
Closes #17422

lib/http_aws_sigv4.c

index 22dbe27577016debb2a7698555a7374f2f404d40..aa8945d3c01e7936086d730c9c39549cea8da448 100644 (file)
@@ -549,23 +549,16 @@ UNITTEST CURLcode canon_path(const char *q, size_t len,
   /* Normalized path will be either the same or shorter than the original
    * path, plus trailing slash */
 
-  if(do_uri_encode) {
+  if(do_uri_encode)
     result = uri_encode_path(&original_path, new_path);
-    if(result) {
-      goto fail;
-    }
-  }
-  else {
+  else
     result = curlx_dyn_addn(new_path, q, len);
-    if(result) {
-      goto fail;
-    }
-  }
 
-  if(curlx_dyn_len(new_path) == 0) {
-    result = curlx_dyn_add(new_path, "/");
+  if(!result) {
+    if(curlx_dyn_len(new_path) == 0)
+      result = curlx_dyn_add(new_path, "/");
   }
-fail:
+
   return result;
 }
 
@@ -1079,59 +1072,45 @@ static CURLcode uri_encode_path(struct Curl_str *original_path,
                                 struct dynbuf *new_path)
 {
   const char *p = curlx_str(original_path);
-  CURLcode result = CURLE_OK;
-  size_t index;
+  size_t i;
 
-  for(index = 0; index < curlx_strlen(original_path); index++) {
+  for(i = 0; i < curlx_strlen(original_path); i++) {
     /* Do not encode slashes or unreserved chars from RFC 3986 */
-    unsigned char c = p[index];
-    if(is_reserved_char(c) || c == '/') {
+    CURLcode result = CURLE_OK;
+    unsigned char c = p[i];
+    if(is_reserved_char(c) || c == '/')
       result = curlx_dyn_addn(new_path, &c, 1);
-      if(result) {
-        goto fail;
-      }
-    }
-    else {
+    else
       result = curlx_dyn_addf(new_path, "%%%02X", c);
-      if(result) {
-        goto fail;
-      }
-    }
+    if(result)
+      return result;
   }
-fail:
-  return result;
+
+  return CURLE_OK;
 }
 
 
 static CURLcode encode_query_component(char *component, size_t len,
                                        struct dynbuf *db)
 {
-  size_t index;
-  CURLcode result = CURLE_OK;
-  unsigned char this_char;
+  size_t i;
+  for(i = 0; i < len; i++) {
+    CURLcode result = CURLE_OK;
+    unsigned char this_char = component[i];
 
-  for(index = 0; index < len; index++) {
-
-    this_char = component[index];
-
-    if(is_reserved_char(this_char)) {
+    if(is_reserved_char(this_char))
       /* Escape unreserved chars from RFC 3986 */
       result = curlx_dyn_addn(db, &this_char, 1);
-    }
-    else if(this_char == '+') {
+    else if(this_char == '+')
       /* Encode '+' as space */
       result = curlx_dyn_add(db, "%20");
-    }
-    else {
+    else
       result = curlx_dyn_addf(db, "%%%02X", this_char);
-    }
-    if(result) {
-      goto fail;
-    }
-
+    if(result)
+      return result;
   }
-fail:
-  return result;
+
+  return CURLE_OK;
 }
 
 /*
@@ -1146,12 +1125,10 @@ static CURLcode http_aws_decode_encode(const char *in, size_t in_len,
   CURLcode result =
     Curl_urldecode(in, in_len, &out_s, &out_s_len, REJECT_NADA);
 
-  if(result)
-    goto fail;
-
-  result = encode_query_component(out_s, out_s_len, out);
-  Curl_safefree(out_s);
-fail:
+  if(!result) {
+    result = encode_query_component(out_s, out_s_len, out);
+    Curl_safefree(out_s);
+  }
   return result;
 }