Skip to content

Commit 11e70e9

Browse files
out_azure_logs_ingestion: check snprintf return code
In case of snprintf failures, report an error and fail early. Signed-off-by: Stefano Boriero <[email protected]>
1 parent c2caad6 commit 11e70e9

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

plugins/out_azure_logs_ingestion/azure_logs_ingestion_conf.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
123123
flb_az_li_ctx_destroy(ctx);
124124
return NULL;
125125
}
126-
flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
127-
FLB_AZ_LI_MSIAUTH_URL_TEMPLATE, "", "");
126+
if (flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
127+
FLB_AZ_LI_MSIAUTH_URL_TEMPLATE, "", "") < 0) {
128+
flb_plg_error(ins, "failed to build auth URL for system-assigned managed identity");
129+
flb_az_li_ctx_destroy(ctx);
130+
return NULL;
131+
}
128132
}
129133
else if (ctx->auth_type == FLB_AZ_LI_AUTH_MANAGED_IDENTITY_USER) {
130134
/* User-assigned managed identity */
@@ -136,8 +140,12 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
136140
flb_az_li_ctx_destroy(ctx);
137141
return NULL;
138142
}
139-
flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
140-
FLB_AZ_LI_MSIAUTH_URL_TEMPLATE, "&client_id=", ctx->client_id);
143+
if (flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
144+
FLB_AZ_LI_MSIAUTH_URL_TEMPLATE, "&client_id=", ctx->client_id) < 0) {
145+
flb_plg_error(ins, "failed to build auth URL for user-assigned managed identity");
146+
flb_az_li_ctx_destroy(ctx);
147+
return NULL;
148+
}
141149
}
142150
else {
143151
/* Service principal authentication */
@@ -148,8 +156,12 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
148156
flb_az_li_ctx_destroy(ctx);
149157
return NULL;
150158
}
151-
flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
152-
FLB_AZ_LI_AUTH_URL_TMPLT, ctx->tenant_id);
159+
if (flb_sds_snprintf(&ctx->auth_url, flb_sds_alloc(ctx->auth_url),
160+
FLB_AZ_LI_AUTH_URL_TMPLT, ctx->tenant_id) < 0) {
161+
flb_plg_error(ins, "failed to build auth URL for service principal");
162+
flb_az_li_ctx_destroy(ctx);
163+
return NULL;
164+
}
153165
}
154166

155167
/* Allocate and set dce full url */
@@ -180,8 +192,7 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
180192

181193
/* Create upstream context for Log Ingsetion endpoint */
182194
ctx->u_dce = flb_upstream_create_url(config, ctx->dce_url,
183-
FLB_AZ_LI_TLS_MODE, ins->tls);
184-
if (!ctx->u_dce) {
195+
FLB_AZ_LI_TLS_MODE, ins->tls); if (!ctx->u_dce) {
185196
flb_plg_error(ins, "upstream creation failed");
186197
flb_az_li_ctx_destroy(ctx);
187198
return NULL;

0 commit comments

Comments
 (0)