Summary
In mrbgems/mruby-socket/src/socket.c, mrb_addrinfo_getaddrinfo() accepts Ruby integers for family, socktype, protocol, and flags, then casts them directly to C int before calling getaddrinfo():
hints.ai_flags = (int)flags;
if (mrb_integer_p(family)) {
hints.ai_family = (int)mrb_integer(family);
}
if (mrb_integer_p(socktype)) {
hints.ai_socktype = (int)mrb_integer(socktype);
}
if (mrb_integer_p(protocol)) {
hints.ai_protocol = (int)mrb_integer(protocol);
}
On default 64-bit mruby builds, mrb_int is 64-bit. Out-of-range values are not rejected; they are silently truncated to 32-bit int. After truncation they may collide with valid low socket constants, so getaddrinfo() may proceed with unintended parameters instead of failing validation.
Impact
- Silent numeric truncation / weak input validation.
- Caller-supplied out-of-range integers can become different, still-"valid looking" hint values.
- Not a demonstrated memory-corruption bug, but incorrect argument handling for a public socket API.
Affected
- File:
mrbgems/mruby-socket/src/socket.c
- Function:
mrb_addrinfo_getaddrinfo
- Version tested: latest master @
c04daf59b41d
Summary
In
mrbgems/mruby-socket/src/socket.c,mrb_addrinfo_getaddrinfo()accepts Ruby integers forfamily,socktype,protocol, andflags, then casts them directly to Cintbefore callinggetaddrinfo():On default 64-bit mruby builds,
mrb_intis 64-bit. Out-of-range values are not rejected; they are silently truncated to 32-bitint. After truncation they may collide with valid low socket constants, sogetaddrinfo()may proceed with unintended parameters instead of failing validation.Impact
Affected
mrbgems/mruby-socket/src/socket.cmrb_addrinfo_getaddrinfoc04daf59b41d