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

[transport] detect and warn about unaligned esc sequences #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions sml/src/sml_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len) {
return 0;
}

for (int i=1;i<4;i++){
if (len>i && memcmp(&buf[len-i], esc_seq, 4) == 0){
if (buf[len-i+4] == 0x1a) {
fprintf(stderr, "libsml: warning: unaligned end esc sequence found in data, stream desynced?\n");
} else if (buf[len-i+4] == 0x01) {
fprintf(stderr, "libsml: warning: unaligned (likely) start esc sequence found in data, stream desynced?\n");
} else {
fprintf(stderr, "libsml: warning: unaligned esc sequence found in data, stream desynced?\n");
}
}
}
if (memcmp(&buf[len], esc_seq, 4) == 0) {
// found esc sequence
len += 4;
Expand Down