Prevent packet body overflow
This commit is contained in:
parent
3fa06b40d7
commit
33bf45149e
1 changed files with 8 additions and 2 deletions
10
avr/recv.c
10
avr/recv.c
|
@ -22,7 +22,7 @@ ISR(SPI_STC_vect) {
|
|||
switch (i) {
|
||||
case 0: {
|
||||
if (in == TABBY_PRINTER_SYNC_1) {
|
||||
header.data[0] = in;
|
||||
header.preamble[0] = in;
|
||||
i++;
|
||||
|
||||
b = 0;
|
||||
|
@ -33,7 +33,7 @@ ISR(SPI_STC_vect) {
|
|||
|
||||
case 1: {
|
||||
if (in == TABBY_PRINTER_SYNC_2) {
|
||||
header.data[1] = in;
|
||||
header.preamble[1] = in;
|
||||
i++;
|
||||
} else {
|
||||
i = 0;
|
||||
|
@ -67,6 +67,10 @@ ISR(SPI_STC_vect) {
|
|||
header.size |= in << 8;
|
||||
i++;
|
||||
|
||||
if (header.size > TABBY_PRINTER_PACKET_MAX_SIZE) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -79,6 +83,8 @@ ISR(SPI_STC_vect) {
|
|||
out = TABBY_PRINTER_DEVICE_ID;
|
||||
} else if (b == header.size + 2) {
|
||||
b++;
|
||||
|
||||
out = TABBY_PRINTER_OK;
|
||||
} else if (b == header.size + 3) {
|
||||
i = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue