Skip to content

Conversation

@haydenridd
Copy link

  • Fixed undefined behavior with calling memcpy on nullptr
  • Fixed memory leak in aflib


void af_command_get_value(af_command_t *af_command, uint8_t *value) {
memcpy(value, af_command->value, af_command->value_len);
if(af_command->value_len > 0) {
Copy link
Author

Choose a reason for hiding this comment

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

If this guard isn't here, memcpy regularly gets called with a nullptr for af_command->value. Always with a af_command->value_len = 0, which is why this doesn't cause worse behavior. Technically Undefined Behavior though.

}

void af_lib_destroy(af_lib_t* af_lib) {
queue_free();
Copy link
Author

Choose a reason for hiding this comment

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

Running aflib on Linux with some memory leak detectors caught this one. Memory related to the attribute queue is never freed on af_lib_destroy, this fixes that.

*/
af_lib_error_t af_lib_get_attribute(af_lib_t *af_lib, const uint16_t attr_id) {
uint8_t dummy; // This value isn't actually used.
uint8_t dummy = 0; // This value isn't actually used.
Copy link
Author

Choose a reason for hiding this comment

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

It may not be used, but we still probably shouldn't pass around pointers to uninitialized memory :)

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants