Skip to content

Commit

Permalink
out_s3: fix s3 key tag bug by using sds string
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Pettit <[email protected]>
  • Loading branch information
PettitWesley authored and EC2 Default User committed Jun 8, 2023
1 parent c0e468b commit 6e2adce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions plugins/out_s3/s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file,
struct multipart_upload *m_upload_file, const char *tag, int tag_len)
{
struct upload_queue *upload_contents;
char *tag_cpy;
flb_sds_t tag_cpy;

/* Create upload contents object and add to upload queue */
upload_contents = flb_malloc(sizeof(struct upload_queue));
Expand All @@ -1580,16 +1580,15 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file,
upload_contents->upload_time = -1;

/* Necessary to create separate string for tag to prevent corruption */
tag_cpy = flb_malloc(tag_len);
if (tag_cpy == NULL) {
flb_free(upload_contents);
flb_plg_error(ctx->ins, "Error allocating memory for tag in add_to_queue");
tag_cpy = flb_sds_create_len(tag, tag_len);
if (!tag_cpy) {
flb_errno();
flb_free(upload_contents);
return -1;
}
strncpy(tag_cpy, tag, tag_len);
upload_contents->tag = tag_cpy;


/* Add entry to upload queue */
mk_list_add(&upload_contents->_head, &ctx->upload_queue);
return 0;
Expand All @@ -1599,7 +1598,7 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file,
void remove_from_queue(struct upload_queue *entry)
{
mk_list_del(&entry->_head);
flb_free(entry->tag);
flb_sds_destroy(entry->tag);
flb_free(entry);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/out_s3/s3.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
struct upload_queue {
struct s3_file *upload_file;
struct multipart_upload *m_upload_file;
char *tag;
flb_sds_t tag;
int tag_len;

int retry_counter;
Expand Down

0 comments on commit 6e2adce

Please sign in to comment.