]> granicus.if.org Git - onig/commitdiff
regerror/toascii: do not attempt to serialize NULL pointer
authorDerrick Pallas <derrick@pallas.us>
Sun, 3 Feb 2019 02:38:05 +0000 (18:38 -0800)
committerDerrick Pallas <derrick@pallas.us>
Sun, 3 Feb 2019 02:41:11 +0000 (18:41 -0800)
This has been seen in the wild, e.g.  [1], and while I have not investigated
how a NULL made it in here, this should prevent similar future bugs causing
a SEGFAULT.

[1] https://github.com/stedolan/jq/issues/1803

src/regerror.c

index 3fbcdfee02f99f85aa62b1be9c1dd654c6c3ab06..d4671c070fb9869617d36e35b314f10d35dfcbd7 100644 (file)
@@ -211,7 +211,11 @@ static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
   UChar *p;
   OnigCodePoint code;
 
-  if (ONIGENC_MBC_MINLEN(enc) > 1) {
+  if (!s) {
+    len = 0;
+    *is_over = 0;
+  }
+  else if (ONIGENC_MBC_MINLEN(enc) > 1) {
     p = s;
     len = 0;
     while (p < end) {