Skip to content

Commit 45f9fe3

Browse files
committed
fix build query corner case
1 parent ceaef15 commit 45f9fe3

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

source/client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ static void s_mqtt_client_init(
628628

629629
if (connection->username || connection->metrics_storage) {
630630
struct aws_byte_cursor username_cur;
631+
AWS_ZERO_STRUCT(username_cur);
631632
if (connection->username) {
632633
username_cur = aws_byte_cursor_from_string(connection->username);
633634
}

source/mqtt_iot_sdk_metrics.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ int s_build_username_query(
2525
struct aws_byte_buf *output_username,
2626
size_t *out_full_username_size) {
2727

28+
AWS_ASSERT(base_username);
29+
AWS_ASSERT(params_list);
30+
2831
if (output_username) {
2932
aws_byte_buf_write(output_username, base_username->ptr, base_username_length);
3033
}
@@ -54,15 +57,17 @@ int s_build_username_query(
5457
}
5558

5659
if (output_username) {
57-
if (aws_byte_buf_append(output_username, &param.key) ||
58-
aws_byte_buf_append(output_username, &key_value_delim) ||
59-
aws_byte_buf_append(output_username, &param.value)) {
60+
if (param.key.len > 0 && (aws_byte_buf_append(output_username, &param.key))) {
6061
return AWS_OP_ERR;
6162
}
62-
}
6363

64+
if (param.value.len > 0 && ((aws_byte_buf_append(output_username, &key_value_delim)) ||
65+
aws_byte_buf_append(output_username, &param.value))) {
66+
return AWS_OP_ERR;
67+
}
68+
}
6469
if (out_full_username_size) {
65-
*out_full_username_size += param.key.len + 1 + param.value.len;
70+
*out_full_username_size += param.key.len + param.value.len > 0 ? 1 : 0 + param.value.len;
6671
}
6772
}
6873

0 commit comments

Comments
 (0)