cmark

My personal build of CMark ✏️

Commit
3e0fa0695e26d1d77af8ebc8d70ed8817303a0b3
Parent
1f4632b8e761da5aaeebcefb2e43332ad267dba8
Author
John MacFarlane <jgm@berkeley.edu>
Date

Check for NULL pointer in _scan_at.

Closes #81.

Diffstat

2 files changed, 42 insertions, 38 deletions

Status File Name N° Changes Insertions Deletions
Modified src/scanners.c 66 32 34
Modified src/scanners.re 14 10 4
diff --git a/src/scanners.c b/src/scanners.c
@@ -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;
 }
@@ -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 <= '`') {
diff --git a/src/scanners.re b/src/scanners.re
@@ -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;
 }