]> granicus.if.org Git - onig/commitdiff
NULL pointer check
authorDongao Guo <dongao.guo@intel.com>
Tue, 9 Oct 2018 03:14:11 +0000 (11:14 +0800)
committerDongao Guo <dongao.guo@intel.com>
Tue, 9 Oct 2018 03:31:25 +0000 (11:31 +0800)
These check seems not necessary in logic,it is just to increase
security.

src/regcomp.c
src/regexec.c
src/regparse.c

index 86dac0b7fd60d470d49c9008c91836f59b740295..1686bb264b18561ba08cc3b347655fd436f9a680 100644 (file)
@@ -3558,7 +3558,7 @@ expand_case_fold_string_alt(int item_num, OnigCaseFoldCodeItem items[], UChar *p
       goto mem_err2;
     }
 
-    if (items[i].byte_len != slen) {
+    if (items[i].byte_len != slen && IS_NOT_NULL(var_anode)) {
       Node *rem;
       UChar *q = p + items[i].byte_len;
 
index d298f5b144014d44bc652212e9a1250e7c021cae..871e449e5e9acc5ca3ebd483c24cc8046bf34409 100644 (file)
@@ -4069,6 +4069,7 @@ slow_search_backward(OnigEncoding enc, UChar* target, UChar* target_end,
     s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s);
 
   while (s >= text) {
+    if(IS_NULL(s))break;
     if (*s == *target) {
       p = s + 1;
       t = target + 1;
@@ -4272,6 +4273,7 @@ map_search_backward(OnigEncoding enc, UChar map[],
   const UChar *s = text_start;
 
   while (s >= text) {
+    if(IS_NULL(s))break;
     if (map[*s]) return (UChar* )s;
 
     s = onigenc_get_prev_char_head(enc, adjust_text, s);
@@ -4514,7 +4516,7 @@ backward_search_range(regex_t* reg, const UChar* str, const UChar* end,
       case ANCHOR_BEGIN_LINE:
         if (!ON_STR_BEGIN(p)) {
           prev = onigenc_get_prev_char_head(reg->enc, str, p);
-          if (!ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end)) {
+          if (IS_NOT_NULL(prev) && !ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end)) {
             p = prev;
             goto retry;
           }
@@ -4706,7 +4708,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end,
       UChar* pre_end = ONIGENC_STEP_BACK(reg->enc, str, end, 1);
 
       max_semi_end = (UChar* )end;
-      if (ONIGENC_IS_MBC_NEWLINE(reg->enc, pre_end, end)) {
+      if (IS_NOT_NULL(pre_end) && ONIGENC_IS_MBC_NEWLINE(reg->enc, pre_end, end)) {
         min_semi_end = pre_end;
 
 #ifdef USE_CRNL_AS_LINE_TERMINATOR
@@ -4855,6 +4857,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end,
             MATCH_AND_RETURN_CHECK(orig_start);
             s = prev;
           }
+          if(IS_NULL(s))break;
         } while (s >= range);
         goto mismatch;
       }
index 2e740482a80e8bf0042c58bf2bd7f2787b548521..c7106dda48a73b9f8e08c31071e2dd61780e0dec 100644 (file)
@@ -1562,6 +1562,7 @@ onig_set_callout_of_name(OnigEncoding enc, OnigCalloutType callout_type,
   }
   for (i = arg_num - opt_arg_num, j = 0; i < arg_num; i++, j++) {
     if (fe->arg_types[i] == ONIG_TYPE_STRING) {
+      if(IS_NULL(opt_defaults))return ONIGERR_INVALID_ARGUMENT;
       OnigValue* val = opt_defaults + j;
       UChar* ds = onigenc_strdup(enc, val->s.start, val->s.end);
       CHECK_NULL_RETURN_MEMERR(ds);