Skip to content

Commit

Permalink
Check for NULL pointer in _scan_at.
Browse files Browse the repository at this point in the history
Closes #81.
  • Loading branch information
jgm committed Sep 16, 2015
1 parent 1f4632b commit 3e0fa06
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
66 changes: 32 additions & 34 deletions src/scanners.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c,
bufsize_t offset) {
bufsize_t res;
unsigned char *ptr = (unsigned char *)c->data;
unsigned char lim = ptr[c->len];
unsigned char zero = '\0';

ptr[c->len] = '\0';
res = scanner(ptr + offset);
ptr[c->len] = lim;
if (ptr == NULL) {
res = scanner(&zero);
} else {
unsigned char lim = ptr[c->len];

ptr[c->len] = '\0';
res = scanner(ptr + offset);
ptr[c->len] = lim;
}

return res;
}
Expand Down Expand Up @@ -15122,45 +15128,37 @@ bufsize_t _scan_html_tag(const unsigned char *p) {
unsigned char yych;
static const unsigned char yybm[] = {
/* table 1 .. 8: 0 */
0, 230, 230, 230, 230, 230, 230, 230, 230, 199, 199, 199, 199, 199,
0, 230, 230, 230, 230, 230, 230, 230, 230, 199, 199, 199, 199, 199, 230,
230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230,
230, 230, 230, 230, 199, 230, 70, 230, 230, 230, 230, 134, 230, 230,
230, 230, 230, 254, 246, 230, 254, 254, 254, 254, 254, 254, 254, 254,
254, 254, 246, 230, 198, 198, 196, 230, 230, 254, 254, 254, 254, 254,
230, 230, 230, 199, 230, 70, 230, 230, 230, 230, 134, 230, 230, 230,
230, 230, 254, 246, 230, 254, 254, 254, 254, 254, 254, 254, 254, 254,
254, 246, 230, 198, 198, 196, 230, 230, 254, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 254, 254, 230, 230, 226, 230, 246, 198, 254,
254, 254, 254, 254, 254, 254, 230, 230, 226, 230, 246, 198, 254, 254,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 230, 230, 230,
230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 230, 230, 230, 230,
230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* table 9 .. 11: 256 */
0, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
0, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 32, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 128, 160, 224, 224, 224, 224, 224,
160, 160, 32, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 128, 160, 224, 224, 224, 224, 224, 224,
224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224,
224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 160, 160, 160,
224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
yych = *(marker = p);
if (yych <= '`') {
Expand Down
14 changes: 10 additions & 4 deletions src/scanners.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c,
{
bufsize_t res;
unsigned char *ptr = (unsigned char *)c->data;
unsigned char lim = ptr[c->len];
unsigned char zero = '\0';

ptr[c->len] = '\0';
res = scanner(ptr + offset);
ptr[c->len] = lim;
if (ptr == NULL) {
res = scanner(&zero);
} else {
unsigned char lim = ptr[c->len];

ptr[c->len] = '\0';
res = scanner(ptr + offset);
ptr[c->len] = lim;
}

return res;
}
Expand Down

0 comments on commit 3e0fa06

Please sign in to comment.