From 28bb06d18e33d8d670edd5f9e3fdf38bf08a5bd6 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Wed, 3 Jun 2020 20:42:46 +0200 Subject: [PATCH] Don't crash on decoding unsupported-attributes --- src/ippmsg.cpp | 8 +++++--- src/ippmsg.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ippmsg.cpp b/src/ippmsg.cpp index ad59572..a0da2f6 100644 --- a/src/ippmsg.cpp +++ b/src/ippmsg.cpp @@ -38,7 +38,7 @@ IppMsg::IppMsg(QNetworkReply* resp) while(!bts.atEnd()) { - if(bts.peekU8() <= IppTag::PrinterAttrs) { + if(bts.peekU8() <= IppTag::UnsupportedAttrs) { if(currentAttrType == IppTag::OpAttrs) { _opAttrs = attrs; @@ -49,6 +49,9 @@ IppMsg::IppMsg(QNetworkReply* resp) else if (currentAttrType == IppTag::PrinterAttrs) { _printerAttrs = attrs; } + else if (currentAttrType == IppTag::UnsupportedAttrs) { + qDebug() << "WARNING: unsupported attrs reported:" << attrs; + } if(bts >>= (uint8_t)IppTag::EndAttrs) { break; @@ -78,12 +81,12 @@ QString IppMsg::consume_attribute(QJsonObject& attrs, Bytestream& data, QString data/tmp_len >> tmp_str; name = tmp_str!="" ? tmp_str.c_str() : lastName; - switch (tag) { case OpAttrs: case JobAttrs: case EndAttrs: case PrinterAttrs: + case UnsupportedAttrs: Q_ASSERT(false); case Integer: case Enum: @@ -245,7 +248,6 @@ Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value) } case Resolution: { - qDebug() << value << value.toObject(); qint32 x = value.toObject()["x"].toInt(); qint32 y = value.toObject()["y"].toInt(); qint8 units = value.toObject()["units"].toInt(); diff --git a/src/ippmsg.h b/src/ippmsg.h index db160a9..6b31af9 100644 --- a/src/ippmsg.h +++ b/src/ippmsg.h @@ -19,6 +19,8 @@ public: JobAttrs = 0x02, EndAttrs = 0x03, PrinterAttrs = 0x04, + UnsupportedAttrs = 0x05, + Unsupported = 0x10, Integer = 0x21, Boolean = 0x22, Enum = 0x23,