From 68c58b46918bb377a8d37a3cd1c9a9ba734390f1 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 1 Feb 2017 10:28:56 +0100 Subject: xmlsecurity: various small cleanups Change-Id: Id713460036331fd9f98fd1eca85ca61f57cf5afe Reviewed-on: https://gerrit.libreoffice.org/33779 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- .../source/helper/documentsignaturemanager.cxx | 9 ++- xmlsecurity/source/helper/ooxmlsecexporter.cxx | 4 +- xmlsecurity/source/helper/pdfsignaturehelper.cxx | 4 +- xmlsecurity/source/pdfio/pdfdocument.cxx | 67 ++++++++++------------ 4 files changed, 36 insertions(+), 48 deletions(-) (limited to 'xmlsecurity') diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 7a263449b2ea..dcee8e4d1f77 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -44,9 +45,7 @@ DocumentSignatureManager::DocumentSignatureManager(const uno::Reference(); return *mpPDFSignatureHelper; } @@ -271,7 +270,7 @@ bool DocumentSignatureManager::add(const uno::Reference& sax::Converter::encodeBase64(aStrBuffer, xCert->getEncoded()); OUString aCertDigest; - if (xmlsecurity::Certificate* pCertificate = dynamic_cast(xCert.get())) + if (auto pCertificate = dynamic_cast(xCert.get())) { OUStringBuffer aBuffer; sax::Converter::encodeBase64(aBuffer, pCertificate->getSHA256Thumbprint()); diff --git a/xmlsecurity/source/helper/ooxmlsecexporter.cxx b/xmlsecurity/source/helper/ooxmlsecexporter.cxx index 9a9b9872640f..8b50019d5c92 100644 --- a/xmlsecurity/source/helper/ooxmlsecexporter.cxx +++ b/xmlsecurity/source/helper/ooxmlsecexporter.cxx @@ -420,9 +420,7 @@ OOXMLSecExporter::OOXMLSecExporter(const uno::Reference& { } -OOXMLSecExporter::~OOXMLSecExporter() -{ -} +OOXMLSecExporter::~OOXMLSecExporter() = default; void OOXMLSecExporter::writeSignature() { diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 120bd3dd53d0..bb281c9d4ed8 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -23,9 +23,7 @@ using namespace ::com::sun::star; -PDFSignatureHelper::PDFSignatureHelper() -{ -} +PDFSignatureHelper::PDFSignatureHelper() = default; bool PDFSignatureHelper::ReadAndVerifySignature(const uno::Reference& xInputStream) { diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx index 899250bd27ae..4a7622e6ea38 100644 --- a/xmlsecurity/source/pdfio/pdfdocument.cxx +++ b/xmlsecurity/source/pdfio/pdfdocument.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef XMLSEC_CRYPTO_NSS #include @@ -71,10 +72,10 @@ public: class PDFNumberElement : public PDFElement { /// Input file start location. - sal_uInt64 m_nOffset; + sal_uInt64 m_nOffset = 0; /// Input file token length. - sal_uInt64 m_nLength; - double m_fValue; + sal_uInt64 m_nLength = 0; + double m_fValue = 0; public: PDFNumberElement(); @@ -92,7 +93,7 @@ class PDFDictionaryElement : public PDFElement /// Key-value pairs when the dictionary is a nested value. std::map m_aItems; /// Offset after the '<<' token. - sal_uInt64 m_nLocation; + sal_uInt64 m_nLocation = 0; /// Position after the '/' token. std::map m_aDictionaryKeyOffset; /// Length of the dictionary key and value, till (before) the next token. @@ -115,7 +116,7 @@ public: class PDFEndDictionaryElement : public PDFElement { /// Offset before the '>>' token. - sal_uInt64 m_nLocation; + sal_uInt64 m_nLocation = 0; public: PDFEndDictionaryElement(); bool Read(SvStream& rStream) override; @@ -170,7 +171,7 @@ public: class PDFArrayElement : public PDFElement { /// Location after the '[' token. - sal_uInt64 m_nOffset; + sal_uInt64 m_nOffset = 0; std::vector m_aElements; public: PDFArrayElement(); @@ -183,7 +184,7 @@ public: class PDFEndArrayElement : public PDFElement { /// Location before the ']' token. - sal_uInt64 m_nOffset; + sal_uInt64 m_nOffset = 0; public: PDFEndArrayElement(); bool Read(SvStream& rStream) override; @@ -1114,7 +1115,7 @@ bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< s if (isdigit(ch) || ch == '-') { // Numbering object: an integer or a real. - PDFNumberElement* pNumberElement = new PDFNumberElement(); + auto pNumberElement = new PDFNumberElement(); rElements.push_back(std::unique_ptr(pNumberElement)); rStream.SeekRel(-1); if (!pNumberElement->Read(rStream)) @@ -2097,7 +2098,7 @@ bad_data: } if (!num_bytes) ++num_bytes; /* use one byte for a zero value */ - if (num_bytes + result_bytes > sizeof result) + if (static_cast(num_bytes) + result_bytes > sizeof result) goto bad_data; tmp = num_bytes; rp = result + result_bytes - 1; @@ -2234,7 +2235,10 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat bool bNonDetached = pSubFilter && pSubFilter->GetValue() == "adbe.pkcs7.sha1"; if (!pSubFilter || (pSubFilter->GetValue() != "adbe.pkcs7.detached" && !bNonDetached && pSubFilter->GetValue() != "ETSI.CAdES.detached")) { - SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: unsupported sub-filter: '"<GetValue()<<"'"); + if (!pSubFilter) + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: missing sub-filter"); + else + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: unsupported sub-filter: '"<GetValue()<<"'"); return false; } @@ -2315,7 +2319,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat return false; } // 2 is the leading "<" and the trailing ">" around the hex string. - size_t nSignatureLength = pContents->GetValue().getLength() + 2; + size_t nSignatureLength = static_cast(pContents->GetValue().getLength()) + 2; if (aByteRanges[1].first != (aByteRanges[0].second + nSignatureLength)) { SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: second range start is not the end of the signature"); @@ -2363,7 +2367,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat return false; } - NSSCMSSignedData* pCMSSignedData = static_cast(NSS_CMSContentInfo_GetContent(pCMSContentInfo)); + auto pCMSSignedData = static_cast(NSS_CMSContentInfo_GetContent(pCMSContentInfo)); if (!pCMSSignedData) { SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: NSS_CMSContentInfo_GetContent() failed"); @@ -2778,12 +2782,7 @@ bool PDFCommentElement::Read(SvStream& rStream) return false; } -PDFNumberElement::PDFNumberElement() - : m_nOffset(0), - m_nLength(0), - m_fValue(0) -{ -} +PDFNumberElement::PDFNumberElement() = default; bool PDFNumberElement::Read(SvStream& rStream) { @@ -2946,10 +2945,7 @@ bool PDFObjectElement::Read(SvStream& /*rStream*/) return true; } -PDFDictionaryElement::PDFDictionaryElement() - : m_nLocation(0) -{ -} +PDFDictionaryElement::PDFDictionaryElement() = default; size_t PDFDictionaryElement::Parse(const std::vector< std::unique_ptr >& rElements, PDFElement* pThis, std::map& rDictionary) { @@ -3300,14 +3296,20 @@ void PDFObjectElement::ParseStoredObjects() auto pType = dynamic_cast(Lookup("Type")); if (!pType || pType->GetValue() != "ObjStm") { - SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: missing or unexpected type: " << pType->GetValue()); + if (!pType) + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: missing unexpected type"); + else + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: unexpected type: " << pType->GetValue()); return; } auto pFilter = dynamic_cast(Lookup("Filter")); if (!pFilter || pFilter->GetValue() != "FlateDecode") { - SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: missing or unexpected filter"); + if (!pFilter) + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: missing filter"); + else + SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ReadXRefStream: unexpected filter: " << pFilter->GetValue()); return; } @@ -3393,7 +3395,7 @@ void PDFObjectElement::ParseStoredObjects() size_t nLen = aLengths[nObject]; aStream.Seek(nOffset); - m_aStoredElements.push_back(std::unique_ptr(new PDFObjectElement(m_rDoc, nObjNum, 0))); + m_aStoredElements.push_back(o3tl::make_unique(m_rDoc, nObjNum, 0)); PDFObjectElement* pStored = m_aStoredElements.back().get(); aBuf.clear(); @@ -3561,10 +3563,7 @@ bool PDFDictionaryElement::Read(SvStream& rStream) return true; } -PDFEndDictionaryElement::PDFEndDictionaryElement() - : m_nLocation(0) -{ -} +PDFEndDictionaryElement::PDFEndDictionaryElement() = default; sal_uInt64 PDFEndDictionaryElement::GetLocation() const { @@ -3687,10 +3686,7 @@ bool PDFEndObjectElement::Read(SvStream& /*rStream*/) return true; } -PDFArrayElement::PDFArrayElement() - : m_nOffset(0) -{ -} +PDFArrayElement::PDFArrayElement() = default; bool PDFArrayElement::Read(SvStream& rStream) { @@ -3718,10 +3714,7 @@ const std::vector& PDFArrayElement::GetElements() return m_aElements; } -PDFEndArrayElement::PDFEndArrayElement() - : m_nOffset(0) -{ -} +PDFEndArrayElement::PDFEndArrayElement() = default; bool PDFEndArrayElement::Read(SvStream& rStream) { -- cgit