mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-12-29 17:36:26 -05:00
fw: Add destination buffer size to read()
Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
parent
b292c72534
commit
f386cec1ed
@ -244,7 +244,11 @@ int main()
|
|||||||
|
|
||||||
memset(cmd, 0, CMDLEN_MAXBYTES);
|
memset(cmd, 0, CMDLEN_MAXBYTES);
|
||||||
// Now we know the size of the cmd frame, read it all
|
// Now we know the size of the cmd frame, read it all
|
||||||
read(cmd, hdr.len);
|
if (read(cmd, CMDLEN_MAXBYTES, hdr.len) != 0) {
|
||||||
|
htif_puts("read: buffer overrun\n");
|
||||||
|
forever_redflash();
|
||||||
|
// Not reached
|
||||||
|
}
|
||||||
|
|
||||||
// Is it for us?
|
// Is it for us?
|
||||||
if (hdr.endpoint != DST_FW) {
|
if (hdr.endpoint != DST_FW) {
|
||||||
|
@ -148,9 +148,15 @@ uint8_t readbyte_ledflash(int ledvalue, int loopcount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(uint8_t *buf, size_t nbytes)
|
int read(uint8_t *buf, size_t bufsize, size_t nbytes)
|
||||||
{
|
{
|
||||||
|
if (nbytes > bufsize) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int n = 0; n < nbytes; n++) {
|
for (int n = 0; n < nbytes; n++) {
|
||||||
buf[n] = readbyte();
|
buf[n] = readbyte();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,6 @@ void writebyte(uint8_t b);
|
|||||||
void write(uint8_t *buf, size_t nbytes);
|
void write(uint8_t *buf, size_t nbytes);
|
||||||
uint8_t readbyte();
|
uint8_t readbyte();
|
||||||
uint8_t readbyte_ledflash(int ledvalue, int loopcount);
|
uint8_t readbyte_ledflash(int ledvalue, int loopcount);
|
||||||
void read(uint8_t *buf, size_t nbytes);
|
int read(uint8_t *buf, size_t bufsize, size_t nbytes);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user