Change 33166 by [EMAIL PROTECTED] on 2008/02/01 12:52:40
Integrate:
[ 32997]
Collect all the S_validate_suid() unused argument logic in one place.
[ 32998]
Change 32997 missed one conditionally unused argument.
[ 33000]
Eliminate all PERL_UNUSED_ARG()s in S_validate_suid() by changing its
prototype depending on the compile time options. In turn, this finds
things that are unused in its callers.
[ 33001]
The suidscript argument to S_forbid_setid(), S_open_script() and
S_validate_suid() is actually just a boolean. So make it so.
[ 33002]
Don't create local variables validarg and fdscript if they aren't going
to be used.
Affected files ...
... //depot/maint-5.10/perl/embed.fnc#7 integrate
... //depot/maint-5.10/perl/embed.h#4 integrate
... //depot/maint-5.10/perl/perl.c#5 integrate
... //depot/maint-5.10/perl/perl.h#7 integrate
... //depot/maint-5.10/perl/proto.h#5 integrate
Differences ...
==== //depot/maint-5.10/perl/embed.fnc#7 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#6~33145~ 2008-01-31 02:26:59.000000000 -0800
+++ perl/embed.fnc 2008-02-01 04:52:40.000000000 -0800
@@ -1262,7 +1262,7 @@
#if defined(PERL_IN_PERL_C) || defined(PERL_DECL_PROT)
s |void |find_beginning |NN SV* linestr_sv|NN PerlIO *rsfp
-s |void |forbid_setid |const char flag|const int suidscript
+s |void |forbid_setid |const char flag|const bool suidscript
s |void |incpush |NULLOK const char *dir|bool addsubdirs|bool
addoldvers|bool usesep|bool canrelocate
s |void |init_interp
s |void |init_ids
@@ -1273,12 +1273,25 @@
rs |void |my_exit_jump
s |void |nuke_stacks
s |int |open_script |NN const char *scriptname|bool dosearch \
- |NN SV *sv|NN int *suidscript|NN PerlIO **rsfpp
+ |NN SV *sv|NN bool *suidscript|NN PerlIO **rsfpp
s |void |usage |NN const char *name
-s |void |validate_suid |NN const char *validarg \
+#ifdef DOSUID
+# ifdef IAMSUID
+so |void |validate_suid |NN const char *validarg \
+ |int fdscript \
+ |bool suidscript|NN SV* linestr_sv \
+ |NN PerlIO *rsfp
+# else
+so |void |validate_suid |NN const char *validarg \
|NN const char *scriptname|int fdscript \
- |int suidscript|NN SV* linestr_sv \
+ |NN SV* linestr_sv \
|NN PerlIO *rsfp
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+so |void |validate_suid |NN PerlIO *rsfp
+# endif
+#endif
# if defined(IAMSUID)
s |int |fd_on_nosuid_fs|int fd
==== //depot/maint-5.10/perl/embed.h#4 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#3~33139~ 2008-01-30 15:19:42.000000000 -0800
+++ perl/embed.h 2008-02-01 04:52:40.000000000 -0800
@@ -1259,7 +1259,14 @@
#define nuke_stacks S_nuke_stacks
#define open_script S_open_script
#define usage S_usage
-#define validate_suid S_validate_suid
+#endif
+#ifdef DOSUID
+# ifdef IAMSUID
+# else
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+# endif
#endif
# if defined(IAMSUID)
#ifdef PERL_CORE
@@ -3548,7 +3555,20 @@
#define nuke_stacks() S_nuke_stacks(aTHX)
#define open_script(a,b,c,d,e) S_open_script(aTHX_ a,b,c,d,e)
#define usage(a) S_usage(aTHX_ a)
-#define validate_suid(a,b,c,d,e,f) S_validate_suid(aTHX_ a,b,c,d,e,f)
+#endif
+#ifdef DOSUID
+# ifdef IAMSUID
+#ifdef PERL_CORE
+#endif
+# else
+#ifdef PERL_CORE
+#endif
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+#ifdef PERL_CORE
+#endif
+# endif
#endif
# if defined(IAMSUID)
#ifdef PERL_CORE
==== //depot/maint-5.10/perl/perl.c#5 (text) ====
Index: perl/perl.c
--- perl/perl.c#4~33139~ 2008-01-30 15:19:42.000000000 -0800
+++ perl/perl.c 2008-02-01 04:52:40.000000000 -0800
@@ -125,16 +125,22 @@
static I32 read_e_script(pTHX_ int idx, SV *buf_sv, int maxlen);
-#ifdef IAMSUID
-#ifndef DOSUID
-#define DOSUID
-#endif
-#endif /* IAMSUID */
-
-#ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
#ifdef DOSUID
-#undef DOSUID
-#endif
+# ifdef IAMSUID
+/* Drop scriptname */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv, rsfp) S_validate_suid(aTHX_ validarg, fdscript, suidscript,
linestr_sv, rsfp)
+# else
+/* Drop suidscript */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv, rsfp) S_validate_suid(aTHX_ validarg, scriptname, fdscript,
linestr_sv, rsfp)
+# endif
+#else
+# ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
+/* Drop everything. Heck, don't even try to call it */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv, rsfp) NOOP
+# else
+/* Drop almost everything */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv, rsfp) S_validate_suid(aTHX_ rsfp)
+# endif
#endif
#define CALL_BODY_EVAL(myop) \
@@ -1500,12 +1506,9 @@
PERL_UNUSED_ARG(my_perl);
-#ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
-#ifdef IAMSUID
-#undef IAMSUID
- Perl_croak(aTHX_ "suidperl is no longer needed since the kernel can now
execute\n\
-setuid perl scripts securely.\n");
-#endif /* IAMSUID */
+#ifdef SETUID_SCRIPTS_ARE_SECURE_NOW_AND_IAMSUID
+ Perl_croak(aTHX_ "suidperl is no longer needed since the kernel can now "
+ "execute\nsetuid perl scripts securely.\n");
#endif
#if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT)
@@ -1688,7 +1691,9 @@
char **argv = PL_origargv;
const char *scriptname = NULL;
VOL bool dosearch = FALSE;
+#ifdef DOSUID
const char *validarg = "";
+#endif
register SV *sv;
register char c;
const char *cddir = NULL;
@@ -1778,7 +1783,7 @@
if (argv[1] && !strcmp(argv[1], "Dev:Pseudo"))
break;
#endif
- forbid_setid('e', -1);
+ forbid_setid('e', FALSE);
if (!PL_e_script) {
PL_e_script = newSVpvs("");
add_read_e_script = TRUE;
@@ -1802,7 +1807,7 @@
goto reswitch;
case 'I': /* -I handled both here and in moreswitches() */
- forbid_setid('I', -1);
+ forbid_setid('I', FALSE);
if (!*++s && (s=argv[1]) != NULL) {
argc--,argv++;
}
@@ -1819,13 +1824,13 @@
Perl_croak(aTHX_ "No directory specified for -I");
break;
case 'P':
- forbid_setid('P', -1);
+ forbid_setid('P', FALSE);
PL_preprocess = TRUE;
s++;
deprecate("-P");
goto reswitch;
case 'S':
- forbid_setid('S', -1);
+ forbid_setid('S', FALSE);
dosearch = TRUE;
s++;
goto reswitch;
@@ -2047,9 +2052,12 @@
init_perllib();
{
- int suidscript;
- const int fdscript
- = open_script(scriptname, dosearch, sv, &suidscript, &rsfp);
+ bool suidscript = FALSE;
+
+#ifdef DOSUID
+ const int fdscript =
+#endif
+ open_script(scriptname, dosearch, sv, &suidscript, &rsfp);
validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv, rsfp);
@@ -2077,10 +2085,10 @@
#endif
) {
- /* This will croak if suidscript is >= 0, as -x cannot be used with
+ /* This will croak if suidscript is true, as -x cannot be used with
setuid scripts. */
forbid_setid('x', suidscript);
- /* Hence you can't get here if suidscript >= 0 */
+ /* Hence you can't get here if suidscript is true */
find_beginning(linestr_sv, rsfp);
if (cddir && PerlDir_chdir( (char *)cddir ) < 0)
@@ -3038,7 +3046,7 @@
s++;
return s;
case 'd':
- forbid_setid('d', -1);
+ forbid_setid('d', FALSE);
s++;
/* -dt indicates to the debugger that threads will be used */
@@ -3076,7 +3084,7 @@
case 'D':
{
#ifdef DEBUGGING
- forbid_setid('D', -1);
+ forbid_setid('D', FALSE);
s++;
PL_debug = get_debug_opts( (const char **)&s, 1) | DEBUG_TOP_FLAG;
#else /* !DEBUGGING */
@@ -3112,7 +3120,7 @@
}
return s;
case 'I': /* -I handled both here and in parse_body() */
- forbid_setid('I', -1);
+ forbid_setid('I', FALSE);
++s;
while (*s && isSPACE(*s))
++s;
@@ -3161,10 +3169,10 @@
}
return s;
case 'M':
- forbid_setid('M', -1); /* XXX ? */
+ forbid_setid('M', FALSE); /* XXX ? */
/* FALL THROUGH */
case 'm':
- forbid_setid('m', -1); /* XXX ? */
+ forbid_setid('m', FALSE); /* XXX ? */
if (*++s) {
const char *start;
const char *end;
@@ -3212,7 +3220,7 @@
s++;
return s;
case 's':
- forbid_setid('s', -1);
+ forbid_setid('s', FALSE);
PL_doswitches = TRUE;
s++;
return s;
@@ -3516,7 +3524,7 @@
STATIC int
S_open_script(pTHX_ const char *scriptname, bool dosearch, SV *sv,
- int *suidscript, PerlIO **rsfpp)
+ bool *suidscript, PerlIO **rsfpp)
{
#ifndef IAMSUID
const char *quote;
@@ -3527,8 +3535,6 @@
int fdscript = -1;
dVAR;
- *suidscript = -1;
-
if (PL_e_script) {
PL_origfilename = savepvs("-e");
}
@@ -3551,7 +3557,7 @@
* Is it a mistake to use a similar /dev/fd/ construct for
* suidperl?
*/
- *suidscript = 1;
+ *suidscript = TRUE;
/* PSz 20 Feb 04
* Be supersafe and do some sanity-checks.
* Still, can we be sure we got the right thing?
@@ -3594,7 +3600,7 @@
* perl with that fd as it has always done.
*/
}
- if (*suidscript != 1) {
+ if (*suidscript) {
Perl_croak(aTHX_ "suidperl needs (suid) fd script\n");
}
#else /* IAMSUID */
@@ -3862,11 +3868,20 @@
}
#endif /* IAMSUID */
+#ifdef DOSUID
STATIC void
-S_validate_suid(pTHX_ const char *validarg, const char *scriptname,
- int fdscript, int suidscript, SV *linestr_sv, PerlIO *rsfp)
+S_validate_suid(pTHX_ const char *validarg,
+# ifndef IAMSUID
+ const char *scriptname,
+# endif
+ int fdscript,
+# ifdef IAMSUID
+ bool suidscript,
+# endif
+ SV *linestr_sv, PerlIO *rsfp)
{
dVAR;
+ const char *s, *s2;
/* do we need to emulate setuid on scripts? */
@@ -3895,9 +3910,6 @@
* Configure script will set this up for you if you want it.
*/
-#ifdef DOSUID
- const char *s, *s2;
-
if (PerlLIO_fstat(PerlIO_fileno(rsfp),&PL_statbuf) < 0) /* normal stat
is insecure */
Perl_croak(aTHX_ "Can't stat script \"%s\"",PL_origfilename);
if (PL_statbuf.st_mode & (S_ISUID|S_ISGID)) {
@@ -3906,7 +3918,7 @@
const char *s_end;
# ifdef IAMSUID
- if (fdscript < 0 || suidscript != 1)
+ if (fdscript < 0 || !suidscript)
Perl_croak(aTHX_ "Need (suid) fdscript in suidperl\n"); /* We
already checked this */
/* PSz 11 Nov 03
* Since the script is opened by perl, not suidperl, some of these
@@ -4185,7 +4197,7 @@
# ifdef IAMSUID
else if (PL_preprocess) /* PSz 13 Nov 03 Caught elsewhere, useless(?!)
here */
Perl_croak(aTHX_ "-P not allowed for setuid/setgid script\n");
- else if (fdscript < 0 || suidscript != 1)
+ else if (fdscript < 0 || !suidscript)
/* PSz 13 Nov 03 Caught elsewhere, useless(?!) here */
Perl_croak(aTHX_ "(suid) fdscript needed in suidperl\n");
else {
@@ -4241,13 +4253,18 @@
PERL_FPU_POST_EXEC
Perl_croak(aTHX_ "Can't do setuid (suidperl cannot exec perl)\n");
# endif /* IAMSUID */
+}
+
#else /* !DOSUID */
- PERL_UNUSED_ARG(fdscript);
- PERL_UNUSED_ARG(suidscript);
- if (PL_euid != PL_uid || PL_egid != PL_gid) { /* (suidperl doesn't
exist, in fact) */
+
# ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
- PERL_UNUSED_ARG(rsfp);
+/* Don't even need this function. */
# else
+STATIC void
+S_validate_suid(pTHX_ PerlIO *rsfp)
+{
+ if (PL_euid != PL_uid || PL_egid != PL_gid) { /* (suidperl doesn't
exist, in fact) */
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
PerlLIO_fstat(PerlIO_fileno(rsfp),&PL_statbuf); /* may be either
wrapped or real suid */
if ((PL_euid != PL_uid && PL_euid == PL_statbuf.st_uid &&
PL_statbuf.st_mode & S_ISUID)
||
@@ -4259,11 +4276,9 @@
# endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
/* not set-id, must be wrapped */
}
-#endif /* DOSUID */
- PERL_UNUSED_ARG(validarg);
- PERL_UNUSED_ARG(scriptname);
- PERL_UNUSED_ARG(linestr_sv);
}
+# endif /* SETUID_SCRIPTS_ARE_SECURE_NOW */
+#endif /* DOSUID */
STATIC void
S_find_beginning(pTHX_ SV* linestr_sv, PerlIO *rsfp)
@@ -4402,7 +4417,7 @@
"program input from stdin", which is substituted in place of '\0', which
could never be a command line flag. */
STATIC void
-S_forbid_setid(pTHX_ const char flag, const int suidscript)
+S_forbid_setid(pTHX_ const char flag, const bool suidscript) /* g */
{
dVAR;
char string[3] = "-x";
@@ -4441,7 +4456,7 @@
*
* Also see comments about root running a setuid script, elsewhere.
*/
- if (suidscript >= 0)
+ if (suidscript)
Perl_croak(aTHX_ "No %s allowed with (suid) fdscript", message);
#ifdef IAMSUID
/* PSz 11 Nov 03 Catch it in suidperl, always! */
==== //depot/maint-5.10/perl/perl.h#7 (text) ====
Index: perl/perl.h
--- perl/perl.h#6~33155~ 2008-01-31 13:06:11.000000000 -0800
+++ perl/perl.h 2008-02-01 04:52:40.000000000 -0800
@@ -41,6 +41,24 @@
# endif
#endif
+/* This logic needs to come after reading config.h, but before including
+ proto.h */
+#ifdef IAMSUID
+# ifndef DOSUID
+# define DOSUID
+# endif
+#endif
+
+#ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
+# ifdef DOSUID
+# undef DOSUID
+# endif
+# ifdef IAMSUID
+# undef IAMSUID
+# define SETUID_SCRIPTS_ARE_SECURE_NOW_AND_IAMSUID
+# endif
+#endif
+
/* See L<perlguts/"The Perl API"> for detailed notes on
* PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
==== //depot/maint-5.10/perl/proto.h#5 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#4~33145~ 2008-01-31 02:26:59.000000000 -0800
+++ perl/proto.h 2008-02-01 04:52:40.000000000 -0800
@@ -3393,7 +3393,7 @@
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2);
-STATIC void S_forbid_setid(pTHX_ const char flag, const int suidscript);
+STATIC void S_forbid_setid(pTHX_ const char flag, const bool suidscript);
STATIC void S_incpush(pTHX_ const char *dir, bool addsubdirs, bool
addoldvers, bool usesep, bool canrelocate);
STATIC void S_init_interp(pTHX);
STATIC void S_init_ids(pTHX);
@@ -3407,7 +3407,7 @@
__attribute__noreturn__;
STATIC void S_nuke_stacks(pTHX);
-STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, SV
*sv, int *suidscript, PerlIO **rsfpp)
+STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, SV
*sv, bool *suidscript, PerlIO **rsfpp)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_3)
__attribute__nonnull__(pTHX_4)
@@ -3416,12 +3416,28 @@
STATIC void S_usage(pTHX_ const char *name)
__attribute__nonnull__(pTHX_1);
-STATIC void S_validate_suid(pTHX_ const char *validarg, const char
*scriptname, int fdscript, int suidscript, SV* linestr_sv, PerlIO *rsfp)
+#ifdef DOSUID
+# ifdef IAMSUID
+STATIC void S_validate_suid(pTHX_ const char *validarg, int fdscript, bool
suidscript, SV* linestr_sv, PerlIO *rsfp)
+ __attribute__nonnull__(pTHX_1)
+ __attribute__nonnull__(pTHX_4)
+ __attribute__nonnull__(pTHX_5);
+
+# else
+STATIC void S_validate_suid(pTHX_ const char *validarg, const char
*scriptname, int fdscript, SV* linestr_sv, PerlIO *rsfp)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2)
- __attribute__nonnull__(pTHX_5)
- __attribute__nonnull__(pTHX_6);
+ __attribute__nonnull__(pTHX_4)
+ __attribute__nonnull__(pTHX_5);
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+STATIC void S_validate_suid(pTHX_ PerlIO *rsfp)
+ __attribute__nonnull__(pTHX_1);
+
+# endif
+#endif
# if defined(IAMSUID)
STATIC int S_fd_on_nosuid_fs(pTHX_ int fd);
End of Patch.