Skip to content
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

Change msg router request data size to size_t. #509

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions source/src/cip/cipcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,10 @@ void EncodeEPath(const void *const data,
message->used_message_length - start_length);
}

int DecodePaddedEPath(CipEpath *epath,
const EipUint8 **message) {
EipStatus DecodePaddedEPath(CipEpath *epath,
const EipUint8 **message,
size_t *const bytes_consumed) {
OPENER_ASSERT(bytes_consumed != NULL);
unsigned int number_of_decoded_elements = 0;
const EipUint8 *message_runner = *message;

Expand Down Expand Up @@ -1461,7 +1463,8 @@ int DecodePaddedEPath(CipEpath *epath,
}

*message = message_runner;
return number_of_decoded_elements * 2 + 1; /* number_of_decoded_elements times 2 as every encoding uses 2 bytes */
*bytes_consumed = number_of_decoded_elements * sizeof(CipWord) + 1; /* number_of_decoded_elements times 2 as every encoding uses 2 bytes */
return kEipStatusOk;
}

EipStatus CipCreateService(CipInstance *RESTRICT const instance,
Expand Down
11 changes: 8 additions & 3 deletions source/src/cip/cipcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,15 @@ EipStatus SetAttributeList(CipInstance *instance,
/** @brief Decodes padded EPath
* @param epath EPath object to the receiving element
* @param message pointer to the message to decode
* @return Number of decoded bytes
* @param[out] bytes_decoded Location to store the number of bytes consumed
* from the message buffer.
* @return @link EipStatus kEipStatusOk @endlink if successful, or
* @link EipStatus kEipStatusError @endlink if the path
* could not be parsed.
*/
int DecodePaddedEPath(CipEpath *epath,
const EipUint8 **message);
EipStatus DecodePaddedEPath(CipEpath *epath,
const EipUint8 **message,
size_t *const bytes_decoded);

/** @brief Generic implementation of the CIP Create service
*
Expand Down
18 changes: 10 additions & 8 deletions source/src/cip/cipmessagerouter.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,21 @@ CipError CreateMessageRouterRequestStructure(const EipUint8 *data,
data++;
data_length--;

int number_of_decoded_bytes =
DecodePaddedEPath(&(message_router_request->request_path), &data);
if(number_of_decoded_bytes < 0) {
size_t number_of_decoded_bytes;
const EipStatus path_result =
DecodePaddedEPath(&(message_router_request->request_path),
&data,
&number_of_decoded_bytes);
if(path_result != kEipStatusOk) {
return kCipErrorPathSegmentError;
}

message_router_request->data = data;
message_router_request->request_data_size = data_length -
number_of_decoded_bytes;

if(message_router_request->request_data_size < 0) {
if(number_of_decoded_bytes > data_length) {
return kCipErrorPathSizeInvalid;
} else {
message_router_request->data = data;
message_router_request->request_data_size = data_length -
number_of_decoded_bytes;
return kCipErrorSuccess;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/src/cip/ciptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ typedef struct {
typedef struct {
CipUsint service;
CipEpath request_path;
EipInt16 request_data_size;
size_t request_data_size;
const CipOctet *data;
} CipMessageRouterRequest;

Expand Down
Loading