Skip to content

Commit

Permalink
DCP identify return false if it hasn't handled a request
Browse files Browse the repository at this point in the history
The function pf_dcp_identify_req, would return 1 even if the request
wasn't handled by it, this would lead to replies to invalid requests
sent to the device. Fixing this so that it only returns 1 if the
request being made passes the necessary checks.

Fixed the invalid ident_req array in the gtests, filled with proper
station name, and tests now check if the station name, dcp data length
and dcp block length are correct for packets.
  • Loading branch information
atlowl committed Jul 25, 2021
1 parent 2b595ad commit e45ef6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/common/pf_dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,15 @@ static int pf_dcp_identify_req (
src_pos += sizeof (*p_src_block_hdr); /* Point to the block value */

src_block_len = ntohs (p_src_block_hdr->block_length);
/* Check if we have a valid dcp data length */
if (!(src_dcplen >= (src_pos + src_block_len)))
{
ret = -1;
}
else {
match = true; /* So far so good */
}

match = true; /* So far so good */
while ((ret == 0) && (first || (filter && match)) &&
(src_dcplen >= (src_pos + src_block_len)) &&
(dst_pos < PF_FRAME_BUFFER_SIZE))
Expand Down Expand Up @@ -1948,6 +1955,11 @@ static int pf_dcp_identify_req (
__LINE__);
}

if ((ret <= 0) && (match == false))
{
return ret; /* Not handled, not matched or something went wrong */
}

if (p_buf != NULL)
{
pnal_buf_free (p_buf);
Expand Down
2 changes: 1 addition & 1 deletion src/device/pf_cmina.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ int pf_cmina_dcp_get_req (
*pp_value = (uint8_t *)net->cmina_current_dcp_ase.product_name;
break;
case PF_DCP_SUB_DEV_PROP_NAME:
*p_value_length = sizeof (net->cmina_current_dcp_ase.station_name);
*p_value_length = strlen(net->cmina_current_dcp_ase.station_name);
*pp_value = (uint8_t *)net->cmina_current_dcp_ase.station_name;
break;
case PF_DCP_SUB_DEV_PROP_ID:
Expand Down
2 changes: 1 addition & 1 deletion test/test_dcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static uint8_t get_name_req[] = {

static uint8_t ident_req[] = {
0x01, 0x0e, 0xcf, 0x00, 0x00, 0x00, 0xc8, 0x5b, 0x76, 0xe6, 0x89, 0xdf,
0x88, 0x92, 0xfe, 0xfe, 0x05, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,
0x88, 0x92, 0xfe, 0xfe, 0x05, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x10, 0x02, 0x02, 0x00, 0x0c, 0x72, 0x74, 0x2d, 0x6c, 0x61, 0x62,
0x73, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Expand Down

0 comments on commit e45ef6a

Please sign in to comment.