Skip to content

Commit

Permalink
uid_t and gid_t are narrower than VALUE.
Browse files Browse the repository at this point in the history
Often uid / gid are 16 bit or 32 bit integers, while VALUE are 32
to 64 bits.  They tend to differ in size.  Because rb_ensure expects
its callbacks to take VALUE arguments, narrowing must be done by
hand, otherwise data corruption can happen depending on machine ABI.
  • Loading branch information
shyouhei committed Aug 26, 2019
1 parent 48131a4 commit 5e86b00
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions process.c
Original file line number Diff line number Diff line change
Expand Up @@ -7133,8 +7133,9 @@ p_uid_have_saved_id(void)

#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
static VALUE
p_uid_sw_ensure(rb_uid_t id)
p_uid_sw_ensure(VALUE i)
{
rb_uid_t id = (rb_uid_t/* narrowing */)i;
under_uid_switch = 0;
id = rb_seteuid_core(id);
return UIDT2NUM(id);
Expand Down Expand Up @@ -7246,8 +7247,9 @@ p_gid_have_saved_id(void)

#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
static VALUE
p_gid_sw_ensure(rb_gid_t id)
p_gid_sw_ensure(VALUE i)
{
rb_gid_t id = (rb_gid_t/* narrowing */)i;
under_gid_switch = 0;
id = rb_setegid_core(id);
return GIDT2NUM(id);
Expand Down

0 comments on commit 5e86b00

Please sign in to comment.