Skip to content

BLE Central review (Arduino style) #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

eriknyquist
Copy link
Contributor

No description provided.

Know issues:
1. Memory issue. Some times the memcmp not work correct.
2. Central not complete. But can do scan.
1. Add the auto discover
2. Resolve the connect request was not scheduled issue
3. Implement the read/write request
Note: need change the compiler parameter in platform.txt.
"compiler.c.flags=-c -std=gnu11 -mcpu=quarkse_em -mlittle-endian -g -Os ..." to
"compiler.c.flags=-c -std=gnu11 -mcpu=quarkse_em -mlittle-endian -g -O0"
"compiler.cpp.flags=-c -mcpu=quarkse_em -mlittle-endian -g -Os ..." to
"compiler.cpp.flags=-c -mcpu=quarkse_em -mlittle-endian -g -O0 ..."
BLECharacteristicNodePtr node = link_node_create(characteristicImp);
if (NULL == node)
{
delete[] characteristicImp;
Copy link
Contributor Author

@eriknyquist eriknyquist Oct 24, 2016

Choose a reason for hiding this comment

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

This in undefined behaviour-- memory allocated using new should be freed using delete, not delete []

servicePrevImp->setEndHandle(serviceCurImp->startHandle() - 1);
}

pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pr_debug call on line 709 will crash the system if serviceCurImp is NULL.

Copy link
Contributor

Choose a reason for hiding this comment

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

servicePrevImp not be NULL at here. The line 694 can promise this.

//assert(notifyatt->type() == BLETypeCharacteristic);
pr_debug(LOG_MODULE_APP, "%s1", __FUNCTION__);

chrc->setValue((const unsigned char *)data, length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks to me like chrc will always be NULL... it is set to NULL on line 98, and then it is not modified again. However you attempt to dereference it here, on line 105, which will lead to a system crash.

BLEDescriptorNodePtr node = link_node_create(descriptorImp);
if (NULL == node)
{
delete[] descriptorImp;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undefined behaviour. You cannot use delete [] to free an object that was allocated with new. Use delete.

BLECharacteristicNodePtr node = link_node_create(characteristicImp);
if (NULL == node)
{
delete[] characteristicImp;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undefined behaviour, use delete not delete []

temp[0] = mac_str[i - 1];
temp[1] = mac_str[i];

bd_addr.val[length] = strtoul(temp, NULL, 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the array val has a size of 6, and it seems that I could cause an overrun (and possibly a crash) by simply passing in a long-enough string (if the string is long enough, then the loop will continue until length == MAX_UUID_SIZE, which happens to be 16, not 6).

}
}
}
pr_debug(LOG_MODULE_BLE, "%s-%d:link_existed-%d unused-%p", __FUNCTION__, __LINE__, link_existed, unused);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

line 556 will cause a crash if unused is NULL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only print the value for debug. Can not make the program crash

bt_conn_t* conn = bt_conn_create_le(device.bt_le_address(), device.bt_conn_param());
if (NULL != conn)
{
memcpy(unused, device.bt_le_address(), sizeof(bt_addr_le_t));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

line 565 will cause a crash if unused is NULL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed

@kitsunami kitsunami added this to the Castor milestone Oct 24, 2016
@kitsunami
Copy link

Superseded by #337

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

Successfully merging this pull request may close these issues.

4 participants