From: Dan Fandrich Date: Sat, 16 Sep 2023 07:08:26 +0000 (-0700) Subject: http_aws_sigv4: fix sorting with empty parts X-Git-Tag: curl-8_4_0~191 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c87920353883ef9d5aa952e724a8e2589d76add5;p=thirdparty%2Fcurl.git http_aws_sigv4: fix sorting with empty parts 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 --- diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index f39d02cced..25c16a2b76 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -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); }