mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-05-27 07:36:21 +00:00
Ensure UART file descriptors are valid before using them in uart_close ().
The uart_open() function may call uart_close() with a 'serial_port' structure with an invalid member 'fd' if the port was not opened successfully. The call to uart_close() was kept for consistency with the rest of the function because uart_close() is also in charge of freeing 'serial_port'.
This commit is contained in:
@@ -170,8 +170,10 @@ uint32_t uart_get_speed(const serial_port sp)
|
|||||||
|
|
||||||
void uart_close(const serial_port sp)
|
void uart_close(const serial_port sp)
|
||||||
{
|
{
|
||||||
|
if (((serial_port_unix*)sp)->fd >= 0) {
|
||||||
tcsetattr(((serial_port_unix*)sp)->fd,TCSANOW,&((serial_port_unix*)sp)->tiOld);
|
tcsetattr(((serial_port_unix*)sp)->fd,TCSANOW,&((serial_port_unix*)sp)->tiOld);
|
||||||
close(((serial_port_unix*)sp)->fd);
|
close(((serial_port_unix*)sp)->fd);
|
||||||
|
}
|
||||||
free(sp);
|
free(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +335,9 @@ serial_port uart_open(const char* pcPortName)
|
|||||||
|
|
||||||
void uart_close(const serial_port sp)
|
void uart_close(const serial_port sp)
|
||||||
{
|
{
|
||||||
|
if (((serial_port_windows*)sp)->hPort != INVALID_HANDLE_VALUE) {
|
||||||
CloseHandle(((serial_port_windows*)sp)->hPort);
|
CloseHandle(((serial_port_windows*)sp)->hPort);
|
||||||
|
}
|
||||||
free(sp);
|
free(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user