summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaroslaw Kubik <jarek@froglogic.com>2024-03-17 00:06:38 +0100
committerJaroslaw Kubik <jarek@froglogic.com>2024-03-19 12:43:24 +0100
commitc59c317cb8f6c65de6668ba01d61d78feb7d4b9f (patch)
treef7528b08379469d86b4e2770371172aceb0921dd
parent584d0cf335c2c56bfc1cf9f10aa21ea927efae18 (diff)
Prevent misuse of stale errno value in QSerialPort read notifier
Unix syscalls don't modify the value of errno unless they are returning an error code. Thus it is important to check that value only after receiving an erroenus syscall result. The readNotification() which handles incoming serial port data should not treat read() returning 0 as an error - it is not an error and it doesn't update the errno. Consequently, zero-length reads (ie. no data currently available) would use the errno value set by any previous failed syscall. In some cases it led to disabling the read notifier and complete stall of the incoming data stream. Now the zero-length read is handled separately which avoids that problem. Pick-to: 6.7 6.6 6.5 6.2 5.15 Change-Id: I851aff0be7220f8a8f6418ddd40abbdf70d1382b Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r--src/serialport/qserialport_unix.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 1223f824..7e642e57 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -751,7 +751,7 @@ bool QSerialPortPrivate::readNotification()
buffer.chop(bytesToRead - qMax(readBytes, qint64(0)));
- if (readBytes <= 0) {
+ if (readBytes < 0) {
QSerialPortErrorInfo error = getSystemError();
if (error.errorCode != QSerialPort::ResourceError)
error.errorCode = QSerialPort::ReadError;
@@ -759,6 +759,8 @@ bool QSerialPortPrivate::readNotification()
setReadNotificationEnabled(false);
setError(error);
return false;
+ } else if (readBytes == 0) {
+ return false;
}
newBytes = buffer.size() - newBytes;