summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorBrian Fraser <fraserbn@gmail.com>2013-05-23 00:44:15 -0300
committerTony Cook <tony@develop-help.com>2013-06-04 18:45:38 +1000
commitdfff4baff950c3688d6f16335fa1e1037bb84bd0 (patch)
tree93d04ea7777f2ff99152da88b12a87004fdb8671 /pp_sys.c
parentbcbe2b27bd9868685fb7b4a6158b08674d0387cd (diff)
downloadperl-dfff4baff950c3688d6f16335fa1e1037bb84bd0.tar.gz
Stop making assumptions about uids and gids.
The code dealt rather inconsistently with uids and gids. Some places assumed that they could be safely stored in UVs, others in IVs, others in ints; All of them should've been using the macros from config.h instead. Similarly, code that created SVs or pushed values into the stack was also making incorrect assumptions -- As a point of reference, only pp_stat did the right thing: #if Uid_t_size > IVSIZE mPUSHn(PL_statcache.st_uid); #else # if Uid_t_sign <= 0 mPUSHi(PL_statcache.st_uid); # else mPUSHu(PL_statcache.st_uid); # endif #endif The other places were potential bugs, and some were even causing warnings in some unusual OSs, like haiku or qnx. This commit ammends the situation by introducing four new macros, SvUID(), sv_setuid(), SvGID(), and sv_setgid(), and using them where needed.
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c52
1 files changed, 9 insertions, 43 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 9458d2e767..b5efeb448d 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2843,24 +2843,10 @@ PP(pp_stat)
#endif
mPUSHu(PL_statcache.st_mode);
mPUSHu(PL_statcache.st_nlink);
-#if Uid_t_size > IVSIZE
- mPUSHn(PL_statcache.st_uid);
-#else
-# if Uid_t_sign <= 0
- mPUSHi(PL_statcache.st_uid);
-# else
- mPUSHu(PL_statcache.st_uid);
-# endif
-#endif
-#if Gid_t_size > IVSIZE
- mPUSHn(PL_statcache.st_gid);
-#else
-# if Gid_t_sign <= 0
- mPUSHi(PL_statcache.st_gid);
-# else
- mPUSHu(PL_statcache.st_gid);
-# endif
-#endif
+
+ sv_setuid(PUSHmortal, PL_statcache.st_uid);
+ sv_setgid(PUSHmortal, PL_statcache.st_gid);
+
#ifdef USE_STAT_RDEV
mPUSHi(PL_statcache.st_rdev);
#else
@@ -5186,11 +5172,7 @@ PP(pp_gpwent)
PUSHs(sv = sv_newmortal());
if (pwent) {
if (which == OP_GPWNAM)
-# if Uid_t_sign <= 0
- sv_setiv(sv, (IV)pwent->pw_uid);
-# else
- sv_setuv(sv, (UV)pwent->pw_uid);
-# endif
+ sv_setuid(sv, pwent->pw_uid);
else
sv_setpv(sv, pwent->pw_name);
}
@@ -5244,17 +5226,9 @@ PP(pp_gpwent)
SvTAINTED_on(sv);
# endif
-# if Uid_t_sign <= 0
- mPUSHi(pwent->pw_uid);
-# else
- mPUSHu(pwent->pw_uid);
-# endif
+ sv_setuid(PUSHmortal, pwent->pw_uid);
+ sv_setgid(PUSHmortal, pwent->pw_gid);
-# if Uid_t_sign <= 0
- mPUSHi(pwent->pw_gid);
-# else
- mPUSHu(pwent->pw_gid);
-# endif
/* pw_change, pw_quota, and pw_age are mutually exclusive--
* because of the poor interface of the Perl getpw*(),
* not because there's some standard/convention saying so.
@@ -5345,11 +5319,7 @@ PP(pp_ggrent)
PUSHs(sv);
if (grent) {
if (which == OP_GGRNAM)
-#if Gid_t_sign <= 0
- sv_setiv(sv, (IV)grent->gr_gid);
-#else
- sv_setuv(sv, (UV)grent->gr_gid);
-#endif
+ sv_setgid(sv, grent->gr_gid);
else
sv_setpv(sv, grent->gr_name);
}
@@ -5365,11 +5335,7 @@ PP(pp_ggrent)
PUSHs(sv_mortalcopy(&PL_sv_no));
#endif
-#if Gid_t_sign <= 0
- mPUSHi(grent->gr_gid);
-#else
- mPUSHu(grent->gr_gid);
-#endif
+ sv_setgid(PUSHmortal, grent->gr_gid);
#if !(defined(_CRAYMPP) && defined(USE_REENTRANT_API))
/* In UNICOS/mk (_CRAYMPP) the multithreading