|
12 | 12 | #include <stdio.h> |
13 | 13 |
|
14 | 14 | // MQTT payload size https://docs.aws.amazon.com/general/latest/gr/iot-core.html#thing-limits |
15 | | -const int AWS_IOT_MAX_CONTENT_SIZE = 128 * 1024; |
| 15 | +const int AWS_IOT_MAX_USERNAME_SIZE = 128 * 1024; |
16 | 16 | const size_t DEFAULT_QUERY_PARAM_COUNT = 10; |
17 | 17 |
|
18 | 18 | // Build username query string from params_list, the caller is responsible to init and clean up output_username |
@@ -54,9 +54,11 @@ int s_build_username_query( |
54 | 54 | } |
55 | 55 |
|
56 | 56 | if (output_username) { |
57 | | - aws_byte_buf_append(output_username, ¶m.key); |
58 | | - aws_byte_buf_append(output_username, &key_value_delim); |
59 | | - aws_byte_buf_append(output_username, ¶m.value); |
| 57 | + if (aws_byte_buf_append(output_username, ¶m.key) || |
| 58 | + aws_byte_buf_append(output_username, &key_value_delim) || |
| 59 | + aws_byte_buf_append(output_username, ¶m.value)) { |
| 60 | + return AWS_OP_ERR; |
| 61 | + } |
60 | 62 | } |
61 | 63 |
|
62 | 64 | if (out_full_username_size) { |
@@ -85,7 +87,7 @@ int aws_mqtt_append_sdk_metrics_to_username( |
85 | 87 |
|
86 | 88 | /* Build metrics string */ |
87 | 89 | struct aws_byte_buf metrics_string; |
88 | | - if (aws_byte_buf_init(&metrics_string, allocator, AWS_IOT_MAX_CONTENT_SIZE)) { |
| 90 | + if (aws_byte_buf_init(&metrics_string, allocator, AWS_IOT_MAX_USERNAME_SIZE)) { |
89 | 91 | return AWS_OP_ERR; |
90 | 92 | } |
91 | 93 |
|
@@ -149,13 +151,19 @@ int aws_mqtt_append_sdk_metrics_to_username( |
149 | 151 | size_t total_size = 0; |
150 | 152 | s_build_username_query(original_username, base_username_length, ¶ms_list, NULL, &total_size); |
151 | 153 |
|
| 154 | + if (total_size > AWS_IOT_MAX_USERNAME_SIZE) { |
| 155 | + goto cleanup; |
| 156 | + } |
| 157 | + |
152 | 158 | if (output_username && aws_byte_buf_init(output_username, allocator, total_size)) { |
153 | 159 | goto cleanup; |
154 | 160 | } |
155 | 161 |
|
156 | 162 | // build final output username |
157 | | - s_build_username_query( |
158 | | - original_username, base_username_length, ¶ms_list, output_username, out_full_username_size); |
| 163 | + if(s_build_username_query( |
| 164 | + original_username, base_username_length, ¶ms_list, output_username, out_full_username_size)){ |
| 165 | + goto cleanup; |
| 166 | + } |
159 | 167 |
|
160 | 168 | aws_byte_buf_clean_up(&metrics_string); |
161 | 169 | result = AWS_OP_SUCCESS; |
|
0 commit comments