usb_serial: don't allow Service() on a closed device.
- In Service, check that the device is open. - In Close, clear dangling pointers to more easily spot problems and avoid risk of accessing freed memory. Change-Id: I970c4b8b8ec14db448388f74fc275634801c359a Reviewed-on: https://review.haiku-os.org/c/1551 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
865a165f1c
commit
e399a8832d
@@ -212,6 +212,9 @@ SerialDevice::SetModes(struct termios *tios)
|
||||
bool
|
||||
SerialDevice::Service(struct tty *tty, uint32 op, void *buffer, size_t length)
|
||||
{
|
||||
if (!fDeviceOpen)
|
||||
return false;
|
||||
|
||||
if (tty != fMasterTTY)
|
||||
return false;
|
||||
|
||||
@@ -453,6 +456,7 @@ SerialDevice::Close()
|
||||
|
||||
fStopThreads = true;
|
||||
fInputStopped = false;
|
||||
fDeviceOpen = false;
|
||||
|
||||
if (!fDeviceRemoved) {
|
||||
gUSBModule->cancel_queued_transfers(fReadPipe);
|
||||
@@ -473,7 +477,10 @@ SerialDevice::Close()
|
||||
gTTYModule->tty_destroy(fMasterTTY);
|
||||
gTTYModule->tty_destroy(fSlaveTTY);
|
||||
|
||||
fDeviceOpen = false;
|
||||
fMasterTTY = NULL;
|
||||
fSlaveTTY = NULL;
|
||||
fSystemTTYCookie = NULL;
|
||||
fDeviceTTYCookie = NULL;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user