]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http_aws_sigv4: fix sorting with empty parts
authorDan Fandrich <dan@coneharvesters.com>
Sat, 16 Sep 2023 07:08:26 +0000 (00:08 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Sat, 16 Sep 2023 15:35:16 +0000 (08:35 -0700)
When comparing with an empty part, the non-empty one is always
considered greater-than. Previously, the two would be considered equal
which would randomly place empty parts amongst non-empty ones. This
showed as a test 439 failure on Solaris as it uses a different
implementation of qsort() that compares parts differently.

Fixes #11855
Closes #11868

lib/http_aws_sigv4.c

index f39d02ccedbee422626c0c1f2c4233f7647b3de3..25c16a2b7678487a65a3d93d8e7db6b6aa7ac223 100644 (file)
@@ -409,6 +409,11 @@ static int compare_func(const void *a, const void *b)
 {
   const struct pair *aa = a;
   const struct pair *bb = b;
+  /* If one element is empty, the other is always sorted higher */
+  if(aa->len == 0)
+    return -1;
+  if(bb->len == 0)
+    return 1;
   return strncmp(aa->p, bb->p, aa->len < bb->len ? aa->len : bb->len);
 }