Skip to content

Commit

Permalink
crc checking on messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jmberg committed Dec 12, 2018
1 parent 182d1ef commit 362743a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sml/src/sml_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) {
break;
}

sml_file_add_message(file, msg);
if (msg)
sml_file_add_message(file, msg);

}

Expand Down
6 changes: 6 additions & 0 deletions sml/src/sml_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ sml_message *sml_message_parse(sml_buffer *buf) {
.message_body = NULL,
.crc = NULL
};
int msg_start = buf->cursor;
int len;

if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
Expand All @@ -62,8 +64,12 @@ sml_message *sml_message_parse(sml_buffer *buf) {
msg->message_body = sml_message_body_parse(buf);
if (sml_buf_has_errors(buf)) goto error;

len = buf->cursor - msg_start;

msg->crc = sml_u16_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
if (*msg->crc != sml_crc16_calculate(&(buf->buffer[msg_start]), len))
goto error;

if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) {
sml_buf_update_bytes_read(buf, 1);
Expand Down

0 comments on commit 362743a

Please sign in to comment.