Kaydet (Commit) a30b765d authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity: various small cleanups

Reviewed-on: https://gerrit.libreoffice.org/33779Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
(cherry picked from commit 68c58b46)

Conflicts:
	xmlsecurity/source/helper/documentsignaturemanager.cxx
	xmlsecurity/source/helper/pdfsignaturehelper.cxx

Change-Id: Id713460036331fd9f98fd1eca85ca61f57cf5afe
üst fe677e8f
...@@ -426,9 +426,7 @@ OOXMLSecExporter::OOXMLSecExporter(const uno::Reference<uno::XComponentContext>& ...@@ -426,9 +426,7 @@ OOXMLSecExporter::OOXMLSecExporter(const uno::Reference<uno::XComponentContext>&
{ {
} }
OOXMLSecExporter::~OOXMLSecExporter() OOXMLSecExporter::~OOXMLSecExporter() = default;
{
}
void OOXMLSecExporter::writeSignature() void OOXMLSecExporter::writeSignature()
{ {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <unotools/datetime.hxx> #include <unotools/datetime.hxx>
#include <vcl/pdfwriter.hxx> #include <vcl/pdfwriter.hxx>
#include <xmloff/xmluconv.hxx> #include <xmloff/xmluconv.hxx>
#include <o3tl/make_unique.hxx>
#ifdef XMLSEC_CRYPTO_NSS #ifdef XMLSEC_CRYPTO_NSS
#include <cert.h> #include <cert.h>
...@@ -71,10 +72,10 @@ public: ...@@ -71,10 +72,10 @@ public:
class PDFNumberElement : public PDFElement class PDFNumberElement : public PDFElement
{ {
/// Input file start location. /// Input file start location.
sal_uInt64 m_nOffset; sal_uInt64 m_nOffset = 0;
/// Input file token length. /// Input file token length.
sal_uInt64 m_nLength; sal_uInt64 m_nLength = 0;
double m_fValue; double m_fValue = 0;
public: public:
PDFNumberElement(); PDFNumberElement();
...@@ -92,7 +93,7 @@ class PDFDictionaryElement : public PDFElement ...@@ -92,7 +93,7 @@ class PDFDictionaryElement : public PDFElement
/// Key-value pairs when the dictionary is a nested value. /// Key-value pairs when the dictionary is a nested value.
std::map<OString, PDFElement*> m_aItems; std::map<OString, PDFElement*> m_aItems;
/// Offset after the '<<' token. /// Offset after the '<<' token.
sal_uInt64 m_nLocation; sal_uInt64 m_nLocation = 0;
/// Position after the '/' token. /// Position after the '/' token.
std::map<OString, sal_uInt64> m_aDictionaryKeyOffset; std::map<OString, sal_uInt64> m_aDictionaryKeyOffset;
/// Length of the dictionary key and value, till (before) the next token. /// Length of the dictionary key and value, till (before) the next token.
...@@ -115,7 +116,7 @@ public: ...@@ -115,7 +116,7 @@ public:
class PDFEndDictionaryElement : public PDFElement class PDFEndDictionaryElement : public PDFElement
{ {
/// Offset before the '>>' token. /// Offset before the '>>' token.
sal_uInt64 m_nLocation; sal_uInt64 m_nLocation = 0;
public: public:
PDFEndDictionaryElement(); PDFEndDictionaryElement();
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
...@@ -170,7 +171,7 @@ public: ...@@ -170,7 +171,7 @@ public:
class PDFArrayElement : public PDFElement class PDFArrayElement : public PDFElement
{ {
/// Location after the '[' token. /// Location after the '[' token.
sal_uInt64 m_nOffset; sal_uInt64 m_nOffset = 0;
std::vector<PDFElement*> m_aElements; std::vector<PDFElement*> m_aElements;
public: public:
PDFArrayElement(); PDFArrayElement();
...@@ -183,7 +184,7 @@ public: ...@@ -183,7 +184,7 @@ public:
class PDFEndArrayElement : public PDFElement class PDFEndArrayElement : public PDFElement
{ {
/// Location before the ']' token. /// Location before the ']' token.
sal_uInt64 m_nOffset; sal_uInt64 m_nOffset = 0;
public: public:
PDFEndArrayElement(); PDFEndArrayElement();
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
...@@ -1114,7 +1115,7 @@ bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< s ...@@ -1114,7 +1115,7 @@ bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< s
if (isdigit(ch) || ch == '-') if (isdigit(ch) || ch == '-')
{ {
// Numbering object: an integer or a real. // Numbering object: an integer or a real.
PDFNumberElement* pNumberElement = new PDFNumberElement(); auto pNumberElement = new PDFNumberElement();
rElements.push_back(std::unique_ptr<PDFElement>(pNumberElement)); rElements.push_back(std::unique_ptr<PDFElement>(pNumberElement));
rStream.SeekRel(-1); rStream.SeekRel(-1);
if (!pNumberElement->Read(rStream)) if (!pNumberElement->Read(rStream))
...@@ -2110,7 +2111,7 @@ bad_data: ...@@ -2110,7 +2111,7 @@ bad_data:
} }
if (!num_bytes) if (!num_bytes)
++num_bytes; /* use one byte for a zero value */ ++num_bytes; /* use one byte for a zero value */
if (num_bytes + result_bytes > sizeof result) if (static_cast<size_t>(num_bytes) + result_bytes > sizeof result)
goto bad_data; goto bad_data;
tmp = num_bytes; tmp = num_bytes;
rp = result + result_bytes - 1; rp = result + result_bytes - 1;
...@@ -2247,7 +2248,10 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat ...@@ -2247,7 +2248,10 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat
bool bNonDetached = pSubFilter && pSubFilter->GetValue() == "adbe.pkcs7.sha1"; bool bNonDetached = pSubFilter && pSubFilter->GetValue() == "adbe.pkcs7.sha1";
if (!pSubFilter || (pSubFilter->GetValue() != "adbe.pkcs7.detached" && !bNonDetached && pSubFilter->GetValue() != "ETSI.CAdES.detached")) if (!pSubFilter || (pSubFilter->GetValue() != "adbe.pkcs7.detached" && !bNonDetached && pSubFilter->GetValue() != "ETSI.CAdES.detached"))
{ {
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: unsupported sub-filter: '"<<pSubFilter->GetValue()<<"'"); if (!pSubFilter)
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: missing sub-filter");
else
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: unsupported sub-filter: '"<<pSubFilter->GetValue()<<"'");
return false; return false;
} }
...@@ -2328,7 +2332,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat ...@@ -2328,7 +2332,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat
return false; return false;
} }
// 2 is the leading "<" and the trailing ">" around the hex string. // 2 is the leading "<" and the trailing ">" around the hex string.
size_t nSignatureLength = pContents->GetValue().getLength() + 2; size_t nSignatureLength = static_cast<size_t>(pContents->GetValue().getLength()) + 2;
if (aByteRanges[1].first != (aByteRanges[0].second + nSignatureLength)) if (aByteRanges[1].first != (aByteRanges[0].second + nSignatureLength))
{ {
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: second range start is not the end of the signature"); SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: second range start is not the end of the signature");
...@@ -2376,7 +2380,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat ...@@ -2376,7 +2380,7 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat
return false; return false;
} }
NSSCMSSignedData* pCMSSignedData = static_cast<NSSCMSSignedData*>(NSS_CMSContentInfo_GetContent(pCMSContentInfo)); auto pCMSSignedData = static_cast<NSSCMSSignedData*>(NSS_CMSContentInfo_GetContent(pCMSContentInfo));
if (!pCMSSignedData) if (!pCMSSignedData)
{ {
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: NSS_CMSContentInfo_GetContent() failed"); SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: NSS_CMSContentInfo_GetContent() failed");
...@@ -2791,12 +2795,7 @@ bool PDFCommentElement::Read(SvStream& rStream) ...@@ -2791,12 +2795,7 @@ bool PDFCommentElement::Read(SvStream& rStream)
return false; return false;
} }
PDFNumberElement::PDFNumberElement() PDFNumberElement::PDFNumberElement() = default;
: m_nOffset(0),
m_nLength(0),
m_fValue(0)
{
}
bool PDFNumberElement::Read(SvStream& rStream) bool PDFNumberElement::Read(SvStream& rStream)
{ {
...@@ -2959,10 +2958,7 @@ bool PDFObjectElement::Read(SvStream& /*rStream*/) ...@@ -2959,10 +2958,7 @@ bool PDFObjectElement::Read(SvStream& /*rStream*/)
return true; return true;
} }
PDFDictionaryElement::PDFDictionaryElement() PDFDictionaryElement::PDFDictionaryElement() = default;
: m_nLocation(0)
{
}
size_t PDFDictionaryElement::Parse(const std::vector< std::unique_ptr<PDFElement> >& rElements, PDFElement* pThis, std::map<OString, PDFElement*>& rDictionary) size_t PDFDictionaryElement::Parse(const std::vector< std::unique_ptr<PDFElement> >& rElements, PDFElement* pThis, std::map<OString, PDFElement*>& rDictionary)
{ {
...@@ -3313,14 +3309,20 @@ void PDFObjectElement::ParseStoredObjects() ...@@ -3313,14 +3309,20 @@ void PDFObjectElement::ParseStoredObjects()
auto pType = dynamic_cast<PDFNameElement*>(Lookup("Type")); auto pType = dynamic_cast<PDFNameElement*>(Lookup("Type"));
if (!pType || pType->GetValue() != "ObjStm") 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; return;
} }
auto pFilter = dynamic_cast<PDFNameElement*>(Lookup("Filter")); auto pFilter = dynamic_cast<PDFNameElement*>(Lookup("Filter"));
if (!pFilter || pFilter->GetValue() != "FlateDecode") 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; return;
} }
...@@ -3406,7 +3408,7 @@ void PDFObjectElement::ParseStoredObjects() ...@@ -3406,7 +3408,7 @@ void PDFObjectElement::ParseStoredObjects()
size_t nLen = aLengths[nObject]; size_t nLen = aLengths[nObject];
aStream.Seek(nOffset); aStream.Seek(nOffset);
m_aStoredElements.push_back(std::unique_ptr<PDFObjectElement>(new PDFObjectElement(m_rDoc, nObjNum, 0))); m_aStoredElements.push_back(o3tl::make_unique<PDFObjectElement>(m_rDoc, nObjNum, 0));
PDFObjectElement* pStored = m_aStoredElements.back().get(); PDFObjectElement* pStored = m_aStoredElements.back().get();
aBuf.clear(); aBuf.clear();
...@@ -3574,10 +3576,7 @@ bool PDFDictionaryElement::Read(SvStream& rStream) ...@@ -3574,10 +3576,7 @@ bool PDFDictionaryElement::Read(SvStream& rStream)
return true; return true;
} }
PDFEndDictionaryElement::PDFEndDictionaryElement() PDFEndDictionaryElement::PDFEndDictionaryElement() = default;
: m_nLocation(0)
{
}
sal_uInt64 PDFEndDictionaryElement::GetLocation() const sal_uInt64 PDFEndDictionaryElement::GetLocation() const
{ {
...@@ -3700,10 +3699,7 @@ bool PDFEndObjectElement::Read(SvStream& /*rStream*/) ...@@ -3700,10 +3699,7 @@ bool PDFEndObjectElement::Read(SvStream& /*rStream*/)
return true; return true;
} }
PDFArrayElement::PDFArrayElement() PDFArrayElement::PDFArrayElement() = default;
: m_nOffset(0)
{
}
bool PDFArrayElement::Read(SvStream& rStream) bool PDFArrayElement::Read(SvStream& rStream)
{ {
...@@ -3731,10 +3727,7 @@ const std::vector<PDFElement*>& PDFArrayElement::GetElements() ...@@ -3731,10 +3727,7 @@ const std::vector<PDFElement*>& PDFArrayElement::GetElements()
return m_aElements; return m_aElements;
} }
PDFEndArrayElement::PDFEndArrayElement() PDFEndArrayElement::PDFEndArrayElement() = default;
: m_nOffset(0)
{
}
bool PDFEndArrayElement::Read(SvStream& rStream) bool PDFEndArrayElement::Read(SvStream& rStream)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment