-
Notifications
You must be signed in to change notification settings - Fork 1.9k
out_stackdriver: fix multiple memory leaks and potential corruption #11667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2f85893
d4c6c35
6440aed
1c23f97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ | |
|
|
||
| static int fetch_metadata(struct flb_stackdriver *ctx, | ||
| struct flb_upstream *upstream, char *uri, | ||
| char *payload) | ||
| flb_sds_t *payload) | ||
| { | ||
| int ret; | ||
| int ret_code; | ||
|
|
@@ -44,15 +44,15 @@ static int fetch_metadata(struct flb_stackdriver *ctx, | |
| /* If runtime test mode is enabled, add test data */ | ||
| if (ctx->ins->test_mode == FLB_TRUE) { | ||
| if (strcmp(uri, FLB_STD_METADATA_PROJECT_ID_URI) == 0) { | ||
| flb_sds_cat(payload, "fluent-bit-test", 15); | ||
| *payload = flb_sds_cat(*payload, "fluent-bit-test", 15); | ||
| return 0; | ||
| } | ||
| else if (strcmp(uri, FLB_STD_METADATA_ZONE_URI) == 0) { | ||
| flb_sds_cat(payload, "projects/0123456789/zones/fluent", 32); | ||
| *payload = flb_sds_cat(*payload, "projects/0123456789/zones/fluent", 32); | ||
| return 0; | ||
| } | ||
| else if (strcmp(uri, FLB_STD_METADATA_INSTANCE_ID_URI) == 0) { | ||
| flb_sds_cat(payload, "333222111", 9); | ||
| *payload = flb_sds_cat(*payload, "333222111", 9); | ||
| return 0; | ||
| } | ||
| return -1; | ||
|
|
@@ -88,7 +88,7 @@ static int fetch_metadata(struct flb_stackdriver *ctx, | |
| flb_plg_debug(ctx->ins, "HTTP Status=%i", c->resp.status); | ||
| if (c->resp.status == 200) { | ||
| ret_code = 0; | ||
| flb_sds_copy(payload, c->resp.payload, c->resp.payload_size); | ||
| *payload = flb_sds_copy(*payload, c->resp.payload, c->resp.payload_size); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After switching Useful? React with 👍 / 👎. |
||
| } | ||
| else { | ||
| if (c->resp.payload_size > 0) { | ||
|
|
@@ -117,7 +117,7 @@ int gce_metadata_read_token(struct flb_stackdriver *ctx) | |
|
|
||
| uri = flb_sds_cat(uri, ctx->client_email, flb_sds_len(ctx->client_email)); | ||
| uri = flb_sds_cat(uri, "/token", 6); | ||
| ret = fetch_metadata(ctx, ctx->metadata_u, uri, payload); | ||
| ret = fetch_metadata(ctx, ctx->metadata_u, uri, &payload); | ||
| if (ret != 0) { | ||
| flb_plg_error(ctx->ins, "can't fetch token from the metadata server"); | ||
| flb_sds_destroy(payload); | ||
|
|
@@ -147,7 +147,7 @@ int gce_metadata_read_zone(struct flb_stackdriver *ctx) | |
| flb_sds_t zone = NULL; | ||
|
|
||
| ret = fetch_metadata(ctx, ctx->metadata_u, FLB_STD_METADATA_ZONE_URI, | ||
| payload); | ||
| &payload); | ||
| if (ret != 0) { | ||
| flb_plg_error(ctx->ins, "can't fetch zone from the metadata server"); | ||
| flb_sds_destroy(payload); | ||
|
|
@@ -193,7 +193,7 @@ int gce_metadata_read_project_id(struct flb_stackdriver *ctx) | |
| flb_sds_t payload = flb_sds_create_size(4096); | ||
|
|
||
| ret = fetch_metadata(ctx, ctx->metadata_u, | ||
| FLB_STD_METADATA_PROJECT_ID_URI, payload); | ||
| FLB_STD_METADATA_PROJECT_ID_URI, &payload); | ||
| if (ret != 0) { | ||
| flb_plg_error(ctx->ins, "can't fetch project id from the metadata server"); | ||
| flb_sds_destroy(payload); | ||
|
|
@@ -210,7 +210,7 @@ int gce_metadata_read_instance_id(struct flb_stackdriver *ctx) | |
| flb_sds_t payload = flb_sds_create_size(4096); | ||
|
|
||
| ret = fetch_metadata(ctx, ctx->metadata_u, | ||
| FLB_STD_METADATA_INSTANCE_ID_URI, payload); | ||
| FLB_STD_METADATA_INSTANCE_ID_URI, &payload); | ||
| if (ret != 0) { | ||
| flb_plg_error(ctx->ins, "can't fetch instance id from the metadata server"); | ||
| flb_sds_destroy(payload); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 4311
Handle SDS growth failures before returning success.
Lines 47, 51, 55, and 91 assign the result of
flb_sds_cat()orflb_sds_copy()directly to*payloadwithout checking for allocation failures. Both functions return NULL on reallocation failure. If this occurs,*payloadbecomes NULL, but the function returns 0 (success). Downstream code then dereferences the NULL pointer viaflb_sds_len(payload),flb_sds_create(payload), or loop conditions, causing a crash.The codebase already has
flb_sds_cat_safe()implementing the correct pattern: validate the result before reassigning to the caller's buffer and return an error code on failure.💡 Suggested fix pattern (from flb_sds_cat_safe)
Apply the same validation to all three
flb_sds_cat()calls in test mode (lines 47, 51, 55).🤖 Prompt for AI Agents