Skip to content

Commit

Permalink
[transport] detect and warn about unaligned esc sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
r00t- committed Jan 5, 2023
1 parent 559ca1e commit e15b9f7
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit e15b9f7

Please sign in to comment.