summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2017-04-22 19:33:33 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2017-04-22 17:18:49 +0000
commit225ef1baeb0e49f157f3ba1271915e623bd27dd9 (patch)
treea036555373f045f6ad7d1acd48bdd71f01c2c208
parente5dfb098638628b0215e11791bce372a656af390 (diff)
downloadqtserialport-225ef1baeb0e49f157f3ba1271915e623bd27dd9.tar.gz
Fix possible UB in read() under Unix
If the user calls setReadBufferSize() with a value lesser than the current size of the read buffer, then we get UB in readNotification(): readFromPort(nullptr, some_negative_value); Change-Id: Iddf5838c84c8615670285e9883c48f29faacc07e Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_unix.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 8f9f087..4df1fcb 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -773,7 +773,7 @@ bool QSerialPortPrivate::readNotification()
if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) {
bytesToRead = readBufferMaxSize - buffer.size();
- if (bytesToRead == 0) {
+ if (bytesToRead <= 0) {
// Buffer is full. User must read data from the buffer
// before we can read more from the port.
setReadNotificationEnabled(false);