Skip to content
Permalink
Browse files Browse the repository at this point in the history
[ots] Fix (potential) use-after-free bugs
Make sure we don’t try to access the table after deleting it. Not all
the changed files are affected, but I changed them all for the sake of
consistency.
  • Loading branch information
khaledhosny committed Nov 15, 2014
1 parent eaa05ed commit 003c62d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/gasp.cc
Expand Up @@ -11,10 +11,10 @@

#define DROP_THIS_TABLE(...) \
do { \
delete file->gasp; \
file->gasp = 0; \
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
OTS_FAILURE_MSG("Table discarded"); \
delete file->gasp; \
file->gasp = 0; \
} while (0)

namespace ots {
Expand Down
2 changes: 1 addition & 1 deletion src/gdef.cc
Expand Up @@ -231,9 +231,9 @@ bool ParseMarkGlyphSetsDefTable(ots::OpenTypeFile *file, const uint8_t *data,

#define DROP_THIS_TABLE(msg_) \
do { \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
file->gdef->data = 0; \
file->gdef->length = 0; \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
} while (0)

namespace ots {
Expand Down
2 changes: 1 addition & 1 deletion src/gpos.cc
Expand Up @@ -677,9 +677,9 @@ bool ParseExtensionPositioning(const ots::OpenTypeFile *file,

#define DROP_THIS_TABLE(msg_) \
do { \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
file->gpos->data = 0; \
file->gpos->length = 0; \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
} while (0)

namespace ots {
Expand Down
2 changes: 1 addition & 1 deletion src/gsub.cc
Expand Up @@ -530,9 +530,9 @@ bool ParseReverseChainingContextSingleSubstitution(

#define DROP_THIS_TABLE(msg_) \
do { \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
file->gsub->data = 0; \
file->gsub->length = 0; \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
} while (0)

namespace ots {
Expand Down
4 changes: 2 additions & 2 deletions src/hdmx.cc
Expand Up @@ -13,10 +13,10 @@

#define DROP_THIS_TABLE(...) \
do { \
delete file->hdmx; \
file->hdmx = 0; \
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
OTS_FAILURE_MSG("Table discarded"); \
delete file->hdmx; \
file->hdmx = 0; \
} while (0)

namespace ots {
Expand Down
2 changes: 1 addition & 1 deletion src/kern.cc
Expand Up @@ -11,9 +11,9 @@

#define DROP_THIS_TABLE(msg_) \
do { \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
delete file->kern; \
file->kern = 0; \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
} while (0)

namespace ots {
Expand Down
4 changes: 2 additions & 2 deletions src/ltsh.cc
Expand Up @@ -13,10 +13,10 @@

#define DROP_THIS_TABLE(...) \
do { \
delete file->ltsh; \
file->ltsh = 0; \
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
OTS_FAILURE_MSG("Table discarded"); \
delete file->ltsh; \
file->ltsh = 0; \
} while (0)

namespace ots {
Expand Down
2 changes: 1 addition & 1 deletion src/math.cc
Expand Up @@ -518,9 +518,9 @@ bool ParseMathVariantsTable(const ots::OpenTypeFile *file,

#define DROP_THIS_TABLE(msg_) \
do { \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
file->math->data = 0; \
file->math->length = 0; \
OTS_FAILURE_MSG(msg_ ", table discarded"); \
} while (0)

namespace ots {
Expand Down
4 changes: 2 additions & 2 deletions src/vdmx.cc
Expand Up @@ -11,10 +11,10 @@

#define DROP_THIS_TABLE(...) \
do { \
delete file->vdmx; \
file->vdmx = 0; \
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
OTS_FAILURE_MSG("Table discarded"); \
delete file->vdmx; \
file->vdmx = 0; \
} while (0)

namespace ots {
Expand Down
4 changes: 2 additions & 2 deletions src/vorg.cc
Expand Up @@ -13,10 +13,10 @@

#define DROP_THIS_TABLE(...) \
do { \
delete file->vorg; \
file->vorg = 0; \
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
OTS_FAILURE_MSG("Table discarded"); \
delete file->vorg; \
file->vorg = 0; \
} while (0)

namespace ots {
Expand Down

0 comments on commit 003c62d

Please sign in to comment.