Skip to content

Commit

Permalink
out_s3: fix NULL dereference when upload_id is unset
Browse files Browse the repository at this point in the history
When upload_id is not set in create_multipart_upload() (which can occur
in some failure modes), subsequent retries will segfault when checking
this ID in complete_multipart_upload().

This commit simply checks that the upload ID has been set and returns
the usual error code instead of crashing if not. It also logs an error
message for the user.

Discussed in #3838.

Signed-off-by: Aaron Jacobs <[email protected]>
  • Loading branch information
atheriel authored and gautampunhani committed Aug 4, 2021
1 parent a7a8d21 commit 1a0fc10
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/out_s3/s3_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ int complete_multipart_upload(struct flb_s3 *ctx,
struct flb_http_client *c = NULL;
struct flb_aws_client *s3_client;

if (!m_upload->upload_id) {
flb_plg_error(ctx->ins, "Cannot complete multipart upload for key %s: "
"upload ID is unset ", m_upload->s3_key);
return -1;
}

uri = flb_sds_create_size(flb_sds_len(m_upload->s3_key) + 11 +
flb_sds_len(m_upload->upload_id));
if (!uri) {
Expand Down

0 comments on commit 1a0fc10

Please sign in to comment.