uart: prevent from retrieving more than buffer length (potential buffer overflow)

This commit is contained in:
Romuald Conty 2011-02-14 13:23:39 +00:00
parent 287bbfeea3
commit 555c32015c

View file

@ -252,7 +252,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
return DEIO; return DEIO;
} }
// There is something available, read the data // There is something available, read the data
res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRx), byteCount); res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRx), MIN(byteCount, iExpectedByteCount));
iExpectedByteCount -= byteCount; iExpectedByteCount -= byteCount;
// Stop if the OS has some troubles reading the data // Stop if the OS has some troubles reading the data