diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2014-06-12 13:28:26 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-06-12 14:06:50 +0100 |
commit | 540eb29d08729a853d7405b3eb826e02c42c65b9 (patch) | |
tree | 5335e39834d27882962aa34c4c86632ef5c42fa7 /include | |
parent | 7de8049a17a0d2e11a2e298060bb5495d34d357d (diff) |
liblok: check new methods via macros on nSize, not by de-referencing.
We can't check for NULL from beyond the end of a smaller structure.
Change-Id: Id3754bf747c402cf0d767eda5fd4b5ad6b5789e9
Diffstat (limited to 'include')
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 9 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 97acbab80821..657c16c37db6 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -18,6 +18,13 @@ extern "C" typedef struct _LibreOfficeKit LibreOfficeKit; typedef struct _LibreOfficeKitDocument LibreOfficeKitDocument; +// Do we have an extended member in this struct ? +#define LIBREOFFICEKIT_HAS_MEMBER(strct,member,nSize) \ + ((((int)((unsigned char *)&((strct *) 0)->member) + \ + (int)sizeof ((strct *) 0)->member)) <= (nSize)) + +#define LIBREOFFICEKIT_HAS(pKit,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKit,member,(pKit)->nSize) + struct _LibreOfficeKit { int nSize; @@ -28,6 +35,8 @@ struct _LibreOfficeKit char* (*getError) (LibreOfficeKit *pThis); }; +#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocument,member,(pDoc)->nSize) + struct _LibreOfficeKitDocument { int nSize; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 956e3cba6208..ec1131312280 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -45,11 +45,12 @@ public: inline bool saveAsWithOptions(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL) { // available since LibreOffice 4.3 - if (!mpDoc->saveAsWithOptions) + if (!LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, saveAsWithOptions)) return false; return mpDoc->saveAsWithOptions(mpDoc, pUrl, pFormat, pFilterOptions); } + inline LibreOfficeKitDocument *get() { return mpDoc; } }; class Office |