Skip to content

Commit 781aedf

Browse files
committed
tests: internal: fuzzers: aws_credentials_fuzzer: fix incorrect length parameter
The fuzz_http function was passing a hardcoded length of 250 bytes to flb_parse_http_credentials(), but get_null_terminated() may return a shorter string if less data is available. This mismatch could cause the parser to read past the null terminator or into uninitialized memory during fuzzing. Fix by: - Calculate actual response length based on available data - Use strlen(response) to get the actual string length when calling flb_parse_http_credentials() - Add null check for response before using it This prevents out-of-bounds reads and crashes during fuzz testing. Signed-off-by: Eduardo Silva <[email protected]>
1 parent a31157e commit 781aedf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/internal/fuzzers/aws_credentials_fuzzer.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <stdint.h>
21+
#include <string.h>
2122
#include <fluent-bit.h>
2223
#include <fluent-bit/flb_sds.h>
2324
#include <fluent-bit/flb_aws_credentials.h>
@@ -57,7 +58,7 @@ void fuzz_sts(const uint8_t *data, size_t size) {
5758
flb_sds_t s1 = flb_sts_uri(action, role_arn, session_name,
5859
external_id, identity_token);
5960
if (s1 != NULL) {
60-
flb_sds_destroy(s1);
61+
flb_sds_destroy(s1);
6162
}
6263

6364
flb_free(action);
@@ -76,13 +77,17 @@ void fuzz_sts(const uint8_t *data, size_t size) {
7677
void fuzz_http(const uint8_t *data, size_t size) {
7778
time_t expiration;
7879
struct flb_aws_credentials *creds = NULL;
79-
80-
char *response = get_null_terminated(250, &data, &size);
81-
creds = flb_parse_http_credentials(response, 250, &expiration);
82-
if (creds != NULL) {
83-
flb_aws_credentials_destroy(creds);
80+
size_t response_len;
81+
82+
response_len = (size > 250) ? 250 : size;
83+
char *response = get_null_terminated(response_len, &data, &size);
84+
if (response != NULL) {
85+
creds = flb_parse_http_credentials(response, strlen(response), &expiration);
86+
if (creds != NULL) {
87+
flb_aws_credentials_destroy(creds);
88+
}
89+
flb_free(response);
8490
}
85-
flb_free(response);
8691
}
8792

8893

0 commit comments

Comments
 (0)