Skip to content

Commit 003c62d

Browse files
committed
[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.
1 parent eaa05ed commit 003c62d

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

Diff for: src/gasp.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#define DROP_THIS_TABLE(...) \
1313
do { \
14-
delete file->gasp; \
15-
file->gasp = 0; \
1614
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
1715
OTS_FAILURE_MSG("Table discarded"); \
16+
delete file->gasp; \
17+
file->gasp = 0; \
1818
} while (0)
1919

2020
namespace ots {

Diff for: src/gdef.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ bool ParseMarkGlyphSetsDefTable(ots::OpenTypeFile *file, const uint8_t *data,
231231

232232
#define DROP_THIS_TABLE(msg_) \
233233
do { \
234+
OTS_FAILURE_MSG(msg_ ", table discarded"); \
234235
file->gdef->data = 0; \
235236
file->gdef->length = 0; \
236-
OTS_FAILURE_MSG(msg_ ", table discarded"); \
237237
} while (0)
238238

239239
namespace ots {

Diff for: src/gpos.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ bool ParseExtensionPositioning(const ots::OpenTypeFile *file,
677677

678678
#define DROP_THIS_TABLE(msg_) \
679679
do { \
680+
OTS_FAILURE_MSG(msg_ ", table discarded"); \
680681
file->gpos->data = 0; \
681682
file->gpos->length = 0; \
682-
OTS_FAILURE_MSG(msg_ ", table discarded"); \
683683
} while (0)
684684

685685
namespace ots {

Diff for: src/gsub.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ bool ParseReverseChainingContextSingleSubstitution(
530530

531531
#define DROP_THIS_TABLE(msg_) \
532532
do { \
533+
OTS_FAILURE_MSG(msg_ ", table discarded"); \
533534
file->gsub->data = 0; \
534535
file->gsub->length = 0; \
535-
OTS_FAILURE_MSG(msg_ ", table discarded"); \
536536
} while (0)
537537

538538
namespace ots {

Diff for: src/hdmx.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
#define DROP_THIS_TABLE(...) \
1515
do { \
16-
delete file->hdmx; \
17-
file->hdmx = 0; \
1816
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
1917
OTS_FAILURE_MSG("Table discarded"); \
18+
delete file->hdmx; \
19+
file->hdmx = 0; \
2020
} while (0)
2121

2222
namespace ots {

Diff for: src/kern.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
#define DROP_THIS_TABLE(msg_) \
1313
do { \
14+
OTS_FAILURE_MSG(msg_ ", table discarded"); \
1415
delete file->kern; \
1516
file->kern = 0; \
16-
OTS_FAILURE_MSG(msg_ ", table discarded"); \
1717
} while (0)
1818

1919
namespace ots {

Diff for: src/ltsh.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
#define DROP_THIS_TABLE(...) \
1515
do { \
16-
delete file->ltsh; \
17-
file->ltsh = 0; \
1816
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
1917
OTS_FAILURE_MSG("Table discarded"); \
18+
delete file->ltsh; \
19+
file->ltsh = 0; \
2020
} while (0)
2121

2222
namespace ots {

Diff for: src/math.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ bool ParseMathVariantsTable(const ots::OpenTypeFile *file,
518518

519519
#define DROP_THIS_TABLE(msg_) \
520520
do { \
521+
OTS_FAILURE_MSG(msg_ ", table discarded"); \
521522
file->math->data = 0; \
522523
file->math->length = 0; \
523-
OTS_FAILURE_MSG(msg_ ", table discarded"); \
524524
} while (0)
525525

526526
namespace ots {

Diff for: src/vdmx.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#define DROP_THIS_TABLE(...) \
1313
do { \
14-
delete file->vdmx; \
15-
file->vdmx = 0; \
1614
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
1715
OTS_FAILURE_MSG("Table discarded"); \
16+
delete file->vdmx; \
17+
file->vdmx = 0; \
1818
} while (0)
1919

2020
namespace ots {

Diff for: src/vorg.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
#define DROP_THIS_TABLE(...) \
1515
do { \
16-
delete file->vorg; \
17-
file->vorg = 0; \
1816
OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
1917
OTS_FAILURE_MSG("Table discarded"); \
18+
delete file->vorg; \
19+
file->vorg = 0; \
2020
} while (0)
2121

2222
namespace ots {

0 commit comments

Comments
 (0)