summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/io.c b/io.c
index c8c13f85ea9..2fd71e46695 100644
--- a/io.c
+++ b/io.c
@@ -5090,9 +5090,11 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int
fmode |= FMODE_SETENC_BY_BOM;
estr += 4;
len -= 4;
- memcpy(encname, estr, len);
- encname[len] = '\0';
- estr = encname;
+ if (len > 0 && len <= ENCODING_MAXNAMELEN) {
+ memcpy(encname, estr, len);
+ encname[len] = '\0';
+ estr = encname;
+ }
}
idx = rb_enc_find_index(estr);
}