From: Nicholas Clark Date: Fri, 18 Jan 2008 15:28:09 +0000 (+0000) Subject: The suidscript argument to S_forbid_setid(), S_open_script() and X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f20b29985da982221016a5e2fdf979d5ba37b5cf;p=p5sagit%2Fp5-mst-13.2.git The suidscript argument to S_forbid_setid(), S_open_script() and S_validate_suid() is actually just a boolean. So make it so. p4raw-id: //depot/perl@33001 --- diff --git a/embed.fnc b/embed.fnc index 9aa9378..abfc59e 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1264,7 +1264,7 @@ s |void |Slab_to_rw |NN void *op #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 @@ -1275,13 +1275,13 @@ s |void |init_predump_symbols rs |void |my_exit_jump s |void |nuke_stacks s |int |open_script |NN const char *scriptname|bool dosearch \ - |NN int *suidscript|NN PerlIO **rsfpp + |NN bool *suidscript|NN PerlIO **rsfpp s |void |usage |NN const char *name #ifdef DOSUID # ifdef IAMSUID so |void |validate_suid |NN const char *validarg \ |int fdscript \ - |int suidscript|NN SV* linestr_sv \ + |bool suidscript|NN SV* linestr_sv \ |NN PerlIO *rsfp # else so |void |validate_suid |NN const char *validarg \ diff --git a/perl.c b/perl.c index a8f5303..214d666 100644 --- a/perl.c +++ b/perl.c @@ -1767,7 +1767,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) 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; @@ -1791,7 +1791,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) 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++; } @@ -1808,7 +1808,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) Perl_croak(aTHX_ "No directory specified for -I"); break; case 'S': - forbid_setid('S', -1); + forbid_setid('S', FALSE); dosearch = TRUE; s++; goto reswitch; @@ -2030,7 +2030,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) init_perllib(); { - int suidscript; + bool suidscript = FALSE; const int fdscript = open_script(scriptname, dosearch, &suidscript, &rsfp); @@ -2060,10 +2060,10 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) #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) @@ -3017,7 +3017,7 @@ Perl_moreswitches(pTHX_ const char *s) s++; return s; case 'd': - forbid_setid('d', -1); + forbid_setid('d', FALSE); s++; /* -dt indicates to the debugger that threads will be used */ @@ -3055,7 +3055,7 @@ Perl_moreswitches(pTHX_ const char *s) 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 */ @@ -3091,7 +3091,7 @@ Perl_moreswitches(pTHX_ const char *s) } 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; @@ -3140,10 +3140,10 @@ Perl_moreswitches(pTHX_ const char *s) } 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; @@ -3191,7 +3191,7 @@ Perl_moreswitches(pTHX_ const char *s) s++; return s; case 's': - forbid_setid('s', -1); + forbid_setid('s', FALSE); PL_doswitches = TRUE; s++; return s; @@ -3491,13 +3491,11 @@ S_init_main_stash(pTHX) STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, - int *suidscript, PerlIO **rsfpp) + bool *suidscript, PerlIO **rsfpp) { int fdscript = -1; dVAR; - *suidscript = -1; - if (PL_e_script) { PL_origfilename = savepvs("-e"); } @@ -3520,7 +3518,7 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, * 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? @@ -3563,7 +3561,7 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, * 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 */ @@ -3773,7 +3771,7 @@ S_validate_suid(pTHX_ const char *validarg, # endif int fdscript, # ifdef IAMSUID - int suidscript, + bool suidscript, # endif SV *linestr_sv, PerlIO *rsfp) { @@ -3815,7 +3813,7 @@ S_validate_suid(pTHX_ const char *validarg, 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 @@ -4092,7 +4090,7 @@ FIX YOUR KERNEL, OR PUT A C WRAPPER AROUND THIS SCRIPT!\n"); Perl_croak(aTHX_ "Effective UID cannot exec script\n"); /* they can't do this */ } # ifdef IAMSUID - 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 { @@ -4312,7 +4310,7 @@ Perl_doing_taint(int argc, char *argv[], char *envp[]) "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"; @@ -4351,7 +4349,7 @@ S_forbid_setid(pTHX_ const char flag, const int suidscript) * * 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! */ diff --git a/proto.h b/proto.h index 7ffb64a..a226fea 100644 --- a/proto.h +++ b/proto.h @@ -3388,7 +3388,7 @@ STATIC void S_find_beginning(pTHX_ SV* linestr_sv, PerlIO *rsfp) __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); @@ -3402,7 +3402,7 @@ STATIC void S_my_exit_jump(pTHX) __attribute__noreturn__; STATIC void S_nuke_stacks(pTHX); -STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, int *suidscript, PerlIO **rsfpp) +STATIC int S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript, PerlIO **rsfpp) __attribute__nonnull__(pTHX_1) __attribute__nonnull__(pTHX_3) __attribute__nonnull__(pTHX_4); @@ -3412,7 +3412,7 @@ STATIC void S_usage(pTHX_ const char *name) #ifdef DOSUID # ifdef IAMSUID -STATIC void S_validate_suid(pTHX_ const char *validarg, int fdscript, int suidscript, SV* linestr_sv, PerlIO *rsfp) +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);