Change 33168 by [EMAIL PROTECTED] on 2008/02/01 16:10:22
Integrate:
[ 33166]
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.8/perl/embed.fnc#237 integrate
... //depot/maint-5.8/perl/embed.h#181 integrate
... //depot/maint-5.8/perl/perl.c#225 edit
... //depot/maint-5.8/perl/perl.h#174 integrate
... //depot/maint-5.8/perl/proto.h#227 integrate
Differences ...
==== //depot/maint-5.8/perl/embed.fnc#237 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#236~32553~ 2007-11-29 08:00:15.000000000 -0800
+++ perl/embed.fnc 2008-02-01 08:10:22.000000000 -0800
@@ -1159,7 +1159,7 @@
#if defined(PERL_IN_PERL_C) || defined(PERL_DECL_PROT)
s |void |find_beginning |NN SV* linestr_sv
-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
@@ -1170,11 +1170,23 @@
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 SV *sv|NN bool *suidscript
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
+so |void |validate_suid |NN const char *validarg \
|NN const char *scriptname|int fdscript \
- |int suidscript|NN SV* linestr_sv
+ |NN SV* linestr_sv
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+so |void |validate_suid
+# endif
+#endif
+
# if defined(IAMSUID)
s |int |fd_on_nosuid_fs|int fd
# endif
==== //depot/maint-5.8/perl/embed.h#181 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#180~32553~ 2007-11-29 08:00:15.000000000 -0800
+++ perl/embed.h 2008-02-01 08:10:22.000000000 -0800
@@ -1169,7 +1169,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
@@ -3287,7 +3294,20 @@
#define nuke_stacks() S_nuke_stacks(aTHX)
#define open_script(a,b,c,d) S_open_script(aTHX_ a,b,c,d)
#define usage(a) S_usage(aTHX_ a)
-#define validate_suid(a,b,c,d,e) S_validate_suid(aTHX_ a,b,c,d,e)
+#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.8/perl/perl.c#225 (text) ====
Index: perl/perl.c
--- perl/perl.c#224~32992~ 2008-01-17 23:24:06.000000000 -0800
+++ perl/perl.c 2008-02-01 08:10:22.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) S_validate_suid(aTHX_ validarg, fdscript, suidscript, linestr_sv)
+# else
+/* Drop suidscript */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv) S_validate_suid(aTHX_ validarg, scriptname, fdscript, linestr_sv)
+# 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) NOOP
+# else
+/* Drop almost everything (well, almost on 5.10.x. Everything on 5.8.x) */
+# define validate_suid(validarg, scriptname, fdscript, suidscript,
linestr_sv) S_validate_suid(aTHX)
+# endif
#endif
static void
@@ -1566,12 +1572,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)
@@ -1766,7 +1769,9 @@
char **argv = PL_origargv;
const char *scriptname = NULL;
VOL bool dosearch = FALSE;
+#ifdef DOSUID
const char *validarg = "";
+#endif
register SV *sv;
const char *cddir = NULL;
#ifdef USE_SITECUSTOMIZE
@@ -1851,7 +1856,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("");
filter_add(read_e_script, NULL);
@@ -1875,7 +1880,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++;
}
@@ -1892,12 +1897,12 @@
Perl_croak(aTHX_ "No directory specified for -I");
break;
case 'P':
- forbid_setid('P', -1);
+ forbid_setid('P', FALSE);
PL_preprocess = TRUE;
s++;
goto reswitch;
case 'S':
- forbid_setid('S', -1);
+ forbid_setid('S', FALSE);
dosearch = TRUE;
s++;
goto reswitch;
@@ -2125,9 +2130,12 @@
init_perllib();
{
- int suidscript;
- const int fdscript
- = open_script(scriptname, dosearch, sv, &suidscript);
+ bool suidscript = FALSE;
+
+#ifdef DOSUID
+ const int fdscript =
+#endif
+ open_script(scriptname, dosearch, sv, &suidscript);
validate_suid(validarg, scriptname, fdscript, suidscript, linestr_sv);
@@ -2154,10 +2162,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);
if (cddir && PerlDir_chdir( (char *)cddir ) < 0)
@@ -3154,7 +3162,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 */
@@ -3192,7 +3200,7 @@
case 'D':
{
#ifdef DEBUGGING
- forbid_setid('D', -1);
+ forbid_setid('D', FALSE);
s++;
PL_debug = get_debug_opts_flags( &s, 1) | DEBUG_TOP_FLAG;
#else /* !DEBUGGING */
@@ -3228,7 +3236,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;
@@ -3278,10 +3286,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;
@@ -3329,7 +3337,7 @@
s++;
return s;
case 's':
- forbid_setid('s', -1);
+ forbid_setid('s', FALSE);
PL_doswitches = TRUE;
s++;
return s;
@@ -3626,7 +3634,7 @@
STATIC int
S_open_script(pTHX_ const char *scriptname, bool dosearch, SV *sv,
- int *suidscript)
+ bool *suidscript)
{
#ifndef IAMSUID
const char *quote;
@@ -3636,8 +3644,6 @@
#endif
int fdscript = -1;
- *suidscript = -1;
-
if (PL_e_script) {
PL_origfilename = savepvs("-e");
}
@@ -3660,7 +3666,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?
@@ -3703,7 +3709,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 */
@@ -3971,13 +3977,22 @@
}
#endif /* IAMSUID */
+#ifdef DOSUID
STATIC void
-S_validate_suid(pTHX_ const char *validarg, const char *scriptname,
- int fdscript, int suidscript, SV *linestr_sv)
+S_validate_suid(pTHX_ const char *validarg,
+# ifndef IAMSUID
+ const char *scriptname,
+# endif
+ int fdscript,
+# ifdef IAMSUID
+ bool suidscript,
+# endif
+ SV *linestr_sv)
{
#ifdef IAMSUID
/* int which; */
#endif /* IAMSUID */
+ const char *s, *s2;
/* do we need to emulate setuid on scripts? */
@@ -4006,9 +4021,6 @@
* Configure script will set this up for you if you want it.
*/
-#ifdef DOSUID
- const char *s, *s2;
-
if (PerlLIO_fstat(PerlIO_fileno(PL_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)) {
@@ -4017,7 +4029,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
@@ -4296,7 +4308,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 {
@@ -4359,9 +4371,16 @@
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);
+
+# ifdef SETUID_SCRIPTS_ARE_SECURE_NOW
+/* Don't even need this function. */
+# else
+STATIC void
+S_validate_suid(pTHX)
+{
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(PL_rsfp),&PL_statbuf); /* may be
either wrapped or real suid */
@@ -4375,11 +4394,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)
@@ -4516,7 +4533,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 */
{
char string[3] = "-x";
const char *message = "program input from stdin";
@@ -4554,7 +4571,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.8/perl/perl.h#174 (text) ====
Index: perl/perl.h
--- perl/perl.h#173~32544~ 2007-11-28 15:06:16.000000000 -0800
+++ perl/perl.h 2008-02-01 08:10:22.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
+
#if defined(USE_ITHREADS) && defined(USE_5005THREADS)
# include "error: USE_ITHREADS and USE_5005THREADS are incompatible"
#endif
==== //depot/maint-5.8/perl/proto.h#227 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#226~32545~ 2007-11-28 15:35:51.000000000 -0800
+++ perl/proto.h 2008-02-01 08:10:22.000000000 -0800
@@ -387,16 +387,16 @@
PERL_CALLCONV HV* Perl_gv_stashsv(pTHX_ SV* sv, I32 flags);
PERL_CALLCONV void Perl_hv_clear(pTHX_ HV* tb);
PERL_CALLCONV void Perl_hv_delayfree_ent(pTHX_ HV* hv, HE* entry);
-/* PERL_CALLCONV SV* Perl_hv_delete(pTHX_ HV* tb, const char* key, I32 klen,
I32 flags); */
-/* PERL_CALLCONV SV* Perl_hv_delete_ent(pTHX_ HV* tb, SV* key, I32 flags,
U32 hash); */
-/* PERL_CALLCONV bool Perl_hv_exists(pTHX_ HV* tb, const char* key, I32 klen)
+/* PERL_CALLCONV SV* hv_delete(pTHX_ HV* tb, const char* key, I32 klen, I32
flags); */
+/* PERL_CALLCONV SV* hv_delete_ent(pTHX_ HV* tb, SV* key, I32 flags, U32
hash); */
+/* PERL_CALLCONV bool hv_exists(pTHX_ HV* tb, const char* key, I32 klen)
__attribute__warn_unused_result__; */
-/* PERL_CALLCONV bool Perl_hv_exists_ent(pTHX_ HV* tb, SV* key, U32 hash)
+/* PERL_CALLCONV bool hv_exists_ent(pTHX_ HV* tb, SV* key, U32 hash)
__attribute__warn_unused_result__; */
-/* PERL_CALLCONV SV** Perl_hv_fetch(pTHX_ HV* tb, const char* key, I32 klen,
I32 lval); */
-/* PERL_CALLCONV HE* Perl_hv_fetch_ent(pTHX_ HV* tb, SV* key, I32 lval, U32
hash); */
+/* PERL_CALLCONV SV** hv_fetch(pTHX_ HV* tb, const char* key, I32 klen, I32
lval); */
+/* PERL_CALLCONV HE* hv_fetch_ent(pTHX_ HV* tb, SV* key, I32 lval, U32
hash); */
PERL_CALLCONV void* Perl_hv_common(pTHX_ HV* tb, SV* keysv, const char*
key, STRLEN klen, int flags, int action, SV* val, U32 hash);
PERL_CALLCONV void* Perl_hv_common_key_len(pTHX_ HV *hv, const char *key,
I32 klen_i32, const int action, SV *val, const U32 hash);
PERL_CALLCONV void Perl_hv_free_ent(pTHX_ HV* hv, HE* entryK);
@@ -421,9 +421,9 @@
PERL_CALLCONV void Perl_hv_ksplit(pTHX_ HV* hv, IV newmax);
/* PERL_CALLCONV void Perl_hv_magic(pTHX_ HV* hv, GV* gv, int how); */
-/* PERL_CALLCONV SV** Perl_hv_store(pTHX_ HV* tb, const char* key, I32 klen,
SV* val, U32 hash); */
-/* PERL_CALLCONV HE* Perl_hv_store_ent(pTHX_ HV* tb, SV* key, SV* val, U32
hash); */
-/* PERL_CALLCONV SV** Perl_hv_store_flags(pTHX_ HV* tb, const char* key, I32
klen, SV* val, U32 hash, int flags); */
+/* PERL_CALLCONV SV** hv_store(pTHX_ HV* tb, const char* key, I32 klen, SV*
val, U32 hash); */
+/* PERL_CALLCONV HE* hv_store_ent(pTHX_ HV* tb, SV* key, SV* val, U32 hash);
*/
+/* PERL_CALLCONV SV** hv_store_flags(pTHX_ HV* tb, const char* key, I32 klen,
SV* val, U32 hash, int flags); */
PERL_CALLCONV void Perl_hv_undef(pTHX_ HV* tb);
PERL_CALLCONV I32 Perl_ibcmp(pTHX_ const char* a, const char* b, I32 len)
__attribute__pure__;
@@ -1676,7 +1676,7 @@
#if defined(PERL_IN_PERL_C) || defined(PERL_DECL_PROT)
STATIC void S_find_beginning(pTHX_ SV* linestr_sv);
-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);
@@ -1688,9 +1688,21 @@
__attribute__noreturn__;
STATIC void S_nuke_stacks(pTHX);
-STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, SV
*sv, int *suidscript);
+STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, SV
*sv, bool *suidscript);
STATIC void S_usage(pTHX_ const char *name);
-STATIC void S_validate_suid(pTHX_ const char *validarg, const char
*scriptname, int fdscript, int suidscript, SV* linestr_sv);
+#ifdef DOSUID
+# ifdef IAMSUID
+STATIC void S_validate_suid(pTHX_ const char *validarg, int fdscript, bool
suidscript, SV* linestr_sv);
+# else
+STATIC void S_validate_suid(pTHX_ const char *validarg, const char
*scriptname, int fdscript, SV* linestr_sv);
+# endif
+#else
+# ifndef SETUID_SCRIPTS_ARE_SECURE_NOW
+STATIC void S_validate_suid(pTHX);
+
+# endif
+#endif
+
# if defined(IAMSUID)
STATIC int S_fd_on_nosuid_fs(pTHX_ int fd);
# endif
@@ -2417,11 +2429,11 @@
__attribute__pure__;
#endif
+
PERL_CALLCONV void Perl_sys_init(int* argc, char*** argv);
PERL_CALLCONV void Perl_sys_init3(int* argc, char*** argv, char*** env);
PERL_CALLCONV void Perl_sys_term(void);
-
END_EXTERN_C
/*
* ex: set ts=8 sts=4 sw=4 noet:
End of Patch.