mirror of
https://github.com/ruby/ruby.git
synced 2026-10-29 00:46:26 +08:00
Fix a potential out-of-bounds read
This commit is contained in:
1 file changed
+7
-6
Notes:
git
2026-07-09 12:18:28 +00:00
@@ -208,12 +208,12 @@ skip_to_eol(const char *p, const char *pend)
|
||||
(ISSPACE(type) || (type == '#' && (p = skip_to_eol(p, pend), 1)))
|
||||
|
||||
#ifndef NATINT_PACK
|
||||
# define pack_modifiers(p, t, n, e) pack_modifiers(p, t, e)
|
||||
# define pack_modifiers(p, pe, t, n, e) pack_modifiers(p, pe, t, e)
|
||||
#endif
|
||||
static char *
|
||||
pack_modifiers(const char *p, char type, int *natint, int *explicit_endian)
|
||||
static const char *
|
||||
pack_modifiers(const char *p, const char *pend, char type, int *natint, int *explicit_endian)
|
||||
{
|
||||
while (1) {
|
||||
while (p < pend) {
|
||||
switch (*p) {
|
||||
case '_':
|
||||
case '!':
|
||||
@@ -242,6 +242,7 @@ pack_modifiers(const char *p, char type, int *natint, int *explicit_endian)
|
||||
return (char *)p;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@@ -289,7 +290,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
|
||||
#endif
|
||||
|
||||
if (skip_blank(p, type)) continue;
|
||||
p = pack_modifiers(p, type, &natint, &explicit_endian);
|
||||
p = pack_modifiers(p, pend, type, &natint, &explicit_endian);
|
||||
|
||||
if (*p == '*') { /* set data length */
|
||||
len = strchr("@Xxu", type) ? 0
|
||||
@@ -1046,7 +1047,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, VALUE ofs, enum unpack_mode mode)
|
||||
int star = 0;
|
||||
|
||||
if (skip_blank(p, type)) continue;
|
||||
p = pack_modifiers(p, type, &natint, &explicit_endian);
|
||||
p = pack_modifiers(p, pend, type, &natint, &explicit_endian);
|
||||
|
||||
if (p >= pend)
|
||||
len = 1;
|
||||
|
||||
Reference in new issue
Block a user