summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-10-28 23:03:02 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-10-28 23:03:02 -0700
commit67619a5d5c71c44565a9a0413aaf78f9baece528 (patch)
tree7b299e17e91d6cbed62ba00754fdbfd4e2629e32
parent9253c0eab573e5ca0d37e4b1db77d3b0bfcf3be6 (diff)
Disallow bracketed labels nested more than 1000 deep.
For performance reasons. See #166.
-rw-r--r--src/inlines.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/inlines.c b/src/inlines.c
index 26eb02a..9216979 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -594,7 +594,8 @@ static int link_label(subject* subj, chunk *raw_label)
advance(subj); // advance past [
unsigned char c;
- while ((c = peek_char(subj)) && (c != ']' || nestlevel > 0)) {
+ while ((c = peek_char(subj)) &&
+ (c != ']' || (nestlevel > 0 && nestlevel < STACK_LIMIT))) {
switch (c) {
case '`':
tmp = handle_backticks(subj);
@@ -622,7 +623,7 @@ static int link_label(subject* subj, chunk *raw_label)
advance(subj);
}
}
- if (c == ']') {
+ if (nestlevel == 0 && c == ']') {
*raw_label = chunk_dup(&subj->input, startpos + 1, subj->pos - (startpos + 1));
subj->label_nestlevel = 0;
advance(subj); // advance past ]