summaryrefslogtreecommitdiff
path: root/regenc.h
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-12-09 14:19:31 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-12-12 16:21:31 +0900
commitbe18b60c335ea0d557717470826a489939316192 (patch)
tree36a6e89763f92b300092c9ae7ea76bcea71cda36 /regenc.h
parente1f42844a0b2a4dcf4c7338c41ef92f1b45393d8 (diff)
downloadruby-be18b60c335ea0d557717470826a489939316192.tar.gz
Prevent potential buffer overflow on enclen
Follow up of 1d2d25dcadda0764f303183ac091d0c87b432566
Diffstat (limited to 'regenc.h')
-rw-r--r--regenc.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/regenc.h b/regenc.h
index 1c40901054..352a8d7980 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)