Browse Source

Bug fix: Failure or silently missing headers when when S3 request headers were too long

(cherry picked from commit eea6aa781ceb5dbbd362ffd483bd7419d9bfe94d)

Source commit: 03f7b1ae5648f11c72c2cd19e861d44afdb87b6b
Martin Prikryl 1 week ago
parent
commit
3f090174a6
1 changed files with 5 additions and 3 deletions
  1. 5 3
      libs/libs3/src/request.c

+ 5 - 3
libs/libs3/src/request.c

@@ -289,14 +289,13 @@ static int neon_write_func(void * data, const char * buf, size_t len)
 }
 
 
-static S3Status append_amz_header(RequestComputedValues *values,
+static S3Status do_append_amz_header(RequestComputedValues *values,
                                   int addPrefix,
                                   const char *headerName,
                                   const char *headerValue)
 {
     int rawPos = values->amzHeadersRawLength + 1;
-    values->amzHeaders[values->amzHeadersCount++] = &(values->amzHeadersRaw[rawPos]);
-
+    int initPos = rawPos;
     const char *headerStr = headerName;
     
     char headerNameWithPrefix[S3_MAX_METADATA_SIZE - sizeof(": v")];
@@ -331,6 +330,7 @@ static S3Status append_amz_header(RequestComputedValues *values,
     }
     values->amzHeadersRaw[++rawPos] = '\0';
     values->amzHeadersRawLength = rawPos;
+    values->amzHeaders[values->amzHeadersCount++] = &(values->amzHeadersRaw[initPos]);
     return S3StatusOK;
 }
 
@@ -355,6 +355,8 @@ static S3Status compose_amz_headers(const RequestParams *params,
     values->amzHeadersRaw[0] = '\0';
     values->amzHeadersRawLength = 0;
 
+    S3Status status;
+    #define append_amz_header(...) if ((status = do_append_amz_header(__VA_ARGS__)) != S3StatusOK) return status;
     // Check and copy in the x-amz-meta headers
     if (properties) {
         int i;