From be18b60c335ea0d557717470826a489939316192 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 9 Dec 2022 14:19:31 +0900 Subject: [PATCH] Prevent potential buffer overflow on enclen Follow up of 1d2d25dcadda0764f303183ac091d0c87b432566 --- regenc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regenc.h b/regenc.h index 1c409010545530..352a8d79800873 100644 --- a/regenc.h +++ b/regenc.h @@ -91,7 +91,7 @@ typedef struct { #define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL #define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val) -#define enclen(enc,p,e) ((enc->max_enc_len == enc->min_enc_len) ? enc->min_enc_len : ONIGENC_MBC_ENC_LEN(enc,p,e)) +#define enclen(enc,p,e) ((enc->max_enc_len == enc->min_enc_len) ? (p < e ? enc->min_enc_len : 0) : ONIGENC_MBC_ENC_LEN(enc,p,e)) /* character types bit flag */ #define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE)