This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

found bug in dm_distributed_keys_get

dm_distributed_keys_get returns address of local variable 'peer_enc_key';

sdk version: nRF51_SDK_9.0.0_2e23562

in function ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, dm_sec_keyset_t * p_key_dist)

peer_enc_key declared at [device_manager_peripheral.c:2418, device_manager_central.c:2386] as ble_gap_enc_key_t peer_enc_key;

and used at [device_manager_peripheral.c:2427, device_manager_peripheral.c:2450, device_manager_central.c:2413]

p_key_dist->keys_periph.enc_key.p_enc_key = (dm_enc_key_t *)&peer_enc_key;

Parents
  • True , it is a bug. I think that inside the definition of dm_sec_keyset_t, the declaration of of p_enc_key should not be a pointer but instead a full variable like this

    union 
    {
        dm_enc_key_t       p_enc_key;  /**< Pointer to Device Manager encryption information structure. */
    } enc_key;
    

    Then we can read the memory directly into into like this

       err_code = pstorage_load((uint8_t *)& p_key_dist->keys_periph.enc_key.p_enc_key,
                                 &block_handle,
                                 BOND_SIZE,
                                 BOND_STORAGE_OFFSET);
    
Reply
  • True , it is a bug. I think that inside the definition of dm_sec_keyset_t, the declaration of of p_enc_key should not be a pointer but instead a full variable like this

    union 
    {
        dm_enc_key_t       p_enc_key;  /**< Pointer to Device Manager encryption information structure. */
    } enc_key;
    

    Then we can read the memory directly into into like this

       err_code = pstorage_load((uint8_t *)& p_key_dist->keys_periph.enc_key.p_enc_key,
                                 &block_handle,
                                 BOND_SIZE,
                                 BOND_STORAGE_OFFSET);
    
Children
Related