Skip to content

Conversation

@rkel
Copy link
Contributor

@rkel rkel commented Nov 28, 2025

The offset in write_name function used by GAP service was really ignoring offset value.
This commit updates it to use the offset in similar way how it is done in write_appearance function.

Note: We should implement this solution or check if offset == 0.
Current implementation first allows offset > 0 and then totally ignores it when setting the name.

The offset in write_name function used by GAP service
was really ignoring offset value.
This commit updates it to use the offset in similar way
how it is done in write_appearance function.

Signed-off-by: Radosław Koppel <[email protected]>
@sonarqubecloud
Copy link

Comment on lines +123 to +137
const char *current_name = bt_get_name();
size_t current_name_len = strlen(current_name);

if (offset >= CONFIG_BT_DEVICE_NAME_MAX) {
if (offset > current_name_len) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}

if (offset + len > CONFIG_BT_DEVICE_NAME_MAX) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value, buf, len);
memcpy(value, current_name, current_name_len + 1);
memcpy(value + offset, buf, len);

value[len] = '\0';
value[offset + len] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the + offset changes that seem valid, but why do we care about current_name and current_name_len?

size_t current_name_len = strlen(current_name);

if (offset >= CONFIG_BT_DEVICE_NAME_MAX) {
if (offset > current_name_len) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but isn't offset only used in long writes? Which require the characteristic to have BT_GATT_PERM_PREPARE_WRITE, but BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME does not have that?

So in the current implementation, offset cannot be anything but 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants