Fossil SCM

Fix a use-after-free bug in handling of nested inline footnotes. The bug was discovered by fuzzing with <code>'-fsanitize=fuzzer,undefined,address -DFOSSIL_FUZZ'</code> appended to <var>TCCFLAGS</var> in Makefile.in. It's noteworthy that the <code>',undefined,address'</code> part was essential to find the bug (otherwise just 'double-free' was reported). Many thanks to Stephan for documenting the fuzzing procedures and support.

george 2022-04-21 13:16 UTC markdown-footnotes
Commit 31e5df5fa2c6443f71f02b064e988e242579ee1fe406df3307ae373f6beba6c9
2 files changed +2 -2 +3 -2
+2 -2
--- Makefile.in
+++ Makefile.in
@@ -46,11 +46,11 @@
4646
4747
CFLAGS = @CFLAGS@
4848
CFLAGS_INCLUDE = @CFLAGS_INCLUDE@
4949
LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
5050
BCCFLAGS = @CPPFLAGS@ $(CFLAGS)
51
-TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ $(CFLAGS) -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
51
+TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ $(CFLAGS) -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H -fsanitize=fuzzer -DFOSSIL_FUZZ
5252
INSTALLDIR = $(DESTDIR)@prefix@/bin
5353
USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
5454
SQLITE3_SRC.2 = @SQLITE3_SRC.2@
5555
SQLITE3_OBJ.2 = @SQLITE3_OBJ.2@
5656
SQLITE3_SHELL_SRC.2 = @SQLITE3_SHELL_SRC.2@
@@ -61,11 +61,11 @@
6161
# SQLITE3_SHELL_SRC:
6262
# 0=src/shell.c, 1=src/shell-see.c, 2=$(SQLITE3_SHELL_SRC.2)
6363
USE_LINENOISE = @USE_LINENOISE@
6464
USE_MMAN_H = @USE_MMAN_H@
6565
USE_SEE = @USE_SEE@
66
-APPNAME = fossil
66
+APPNAME = fossil-fuzz
6767
6868
.PHONY: all tags
6969
7070
include $(SRCDIR)/main.mk
7171
7272
--- Makefile.in
+++ Makefile.in
@@ -46,11 +46,11 @@
46
47 CFLAGS = @CFLAGS@
48 CFLAGS_INCLUDE = @CFLAGS_INCLUDE@
49 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
50 BCCFLAGS = @CPPFLAGS@ $(CFLAGS)
51 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ $(CFLAGS) -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
52 INSTALLDIR = $(DESTDIR)@prefix@/bin
53 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
54 SQLITE3_SRC.2 = @SQLITE3_SRC.2@
55 SQLITE3_OBJ.2 = @SQLITE3_OBJ.2@
56 SQLITE3_SHELL_SRC.2 = @SQLITE3_SHELL_SRC.2@
@@ -61,11 +61,11 @@
61 # SQLITE3_SHELL_SRC:
62 # 0=src/shell.c, 1=src/shell-see.c, 2=$(SQLITE3_SHELL_SRC.2)
63 USE_LINENOISE = @USE_LINENOISE@
64 USE_MMAN_H = @USE_MMAN_H@
65 USE_SEE = @USE_SEE@
66 APPNAME = fossil
67
68 .PHONY: all tags
69
70 include $(SRCDIR)/main.mk
71
72
--- Makefile.in
+++ Makefile.in
@@ -46,11 +46,11 @@
46
47 CFLAGS = @CFLAGS@
48 CFLAGS_INCLUDE = @CFLAGS_INCLUDE@
49 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
50 BCCFLAGS = @CPPFLAGS@ $(CFLAGS)
51 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ $(CFLAGS) -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H -fsanitize=fuzzer -DFOSSIL_FUZZ
52 INSTALLDIR = $(DESTDIR)@prefix@/bin
53 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
54 SQLITE3_SRC.2 = @SQLITE3_SRC.2@
55 SQLITE3_OBJ.2 = @SQLITE3_OBJ.2@
56 SQLITE3_SHELL_SRC.2 = @SQLITE3_SHELL_SRC.2@
@@ -61,11 +61,11 @@
61 # SQLITE3_SHELL_SRC:
62 # 0=src/shell.c, 1=src/shell-see.c, 2=$(SQLITE3_SHELL_SRC.2)
63 USE_LINENOISE = @USE_LINENOISE@
64 USE_MMAN_H = @USE_MMAN_H@
65 USE_SEE = @USE_SEE@
66 APPNAME = fossil-fuzz
67
68 .PHONY: all tags
69
70 include $(SRCDIR)/main.mk
71
72
+3 -2
--- src/markdown.c
+++ src/markdown.c
@@ -2777,11 +2777,11 @@
27772777
/* inline notes may get appended to rndr.notes.all while rendering */
27782778
while(1){
27792779
struct footnote *aNotes;
27802780
const int N = COUNT_FOOTNOTES( allNotes );
27812781
2782
- /* make a shallow copy of `origin` */
2782
+ /* make a shallow copy of `allNotes` */
27832783
blob_truncate(notes,0);
27842784
blob_appendb(notes, allNotes);
27852785
aNotes = CAST_AS_FOOTNOTES(notes);
27862786
qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
27872787
@@ -2795,13 +2795,14 @@
27952795
if( x->bRndred || !x->nUsed ) continue;
27962796
assert( x->iMark > 0 );
27972797
assert( blob_size(&x->text) );
27982798
blob_truncate(tmp,0);
27992799
2800
- /* `origin` may be altered and extended through this call */
2800
+ /* `allNotes` may be altered and extended through this call */
28012801
parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
28022802
2803
+ x = CAST_AS_FOOTNOTES(allNotes) + j;
28032804
blob_truncate(&x->text,0);
28042805
blob_appendb(&x->text, tmp);
28052806
x->bRndred = 1;
28062807
}
28072808
}
28082809
--- src/markdown.c
+++ src/markdown.c
@@ -2777,11 +2777,11 @@
2777 /* inline notes may get appended to rndr.notes.all while rendering */
2778 while(1){
2779 struct footnote *aNotes;
2780 const int N = COUNT_FOOTNOTES( allNotes );
2781
2782 /* make a shallow copy of `origin` */
2783 blob_truncate(notes,0);
2784 blob_appendb(notes, allNotes);
2785 aNotes = CAST_AS_FOOTNOTES(notes);
2786 qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
2787
@@ -2795,13 +2795,14 @@
2795 if( x->bRndred || !x->nUsed ) continue;
2796 assert( x->iMark > 0 );
2797 assert( blob_size(&x->text) );
2798 blob_truncate(tmp,0);
2799
2800 /* `origin` may be altered and extended through this call */
2801 parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
2802
 
2803 blob_truncate(&x->text,0);
2804 blob_appendb(&x->text, tmp);
2805 x->bRndred = 1;
2806 }
2807 }
2808
--- src/markdown.c
+++ src/markdown.c
@@ -2777,11 +2777,11 @@
2777 /* inline notes may get appended to rndr.notes.all while rendering */
2778 while(1){
2779 struct footnote *aNotes;
2780 const int N = COUNT_FOOTNOTES( allNotes );
2781
2782 /* make a shallow copy of `allNotes` */
2783 blob_truncate(notes,0);
2784 blob_appendb(notes, allNotes);
2785 aNotes = CAST_AS_FOOTNOTES(notes);
2786 qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
2787
@@ -2795,13 +2795,14 @@
2795 if( x->bRndred || !x->nUsed ) continue;
2796 assert( x->iMark > 0 );
2797 assert( blob_size(&x->text) );
2798 blob_truncate(tmp,0);
2799
2800 /* `allNotes` may be altered and extended through this call */
2801 parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
2802
2803 x = CAST_AS_FOOTNOTES(allNotes) + j;
2804 blob_truncate(&x->text,0);
2805 blob_appendb(&x->text, tmp);
2806 x->bRndred = 1;
2807 }
2808 }
2809

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button