mirror of
https://github.com/php/php-src.git
synced 2026-04-28 10:43:30 +02:00
Always use getopt with CGI, never use it for anything else
This commit is contained in:
@@ -69,11 +69,6 @@
|
||||
|
||||
#include "SAPI.h"
|
||||
|
||||
#if MSVC5 || !defined(HAVE_GETOPT)
|
||||
#include "php_getopt.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef ZTS
|
||||
php_core_globals core_globals;
|
||||
#else
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/* Borrowed from Apache NT Port */
|
||||
#include "php.h"
|
||||
|
||||
PHPAPI extern char *optarg;
|
||||
PHPAPI extern int optind;
|
||||
extern int opterr;
|
||||
extern int optopt;
|
||||
|
||||
PHPAPI int getopt(int argc, char* const *argv, const char *optstr);
|
||||
@@ -5,6 +5,6 @@ srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
LTLIBRARY_NAME = libsapi.la
|
||||
LTLIBRARY_SOURCES = cgi_main.c
|
||||
LTLIBRARY_SOURCES = cgi_main.c getopt.c
|
||||
|
||||
include $(topsrcdir)/build/ltlib.mk
|
||||
|
||||
+15
-17
@@ -70,9 +70,7 @@
|
||||
#include "zend_indent.h"
|
||||
|
||||
|
||||
#if MSVC5 || !defined(HAVE_GETOPT)
|
||||
#include "php_getopt.h"
|
||||
#endif
|
||||
|
||||
PHPAPI extern char *php_ini_path;
|
||||
|
||||
@@ -80,8 +78,8 @@ PHPAPI extern char *php_ini_path;
|
||||
#define PHP_MODE_HIGHLIGHT 2
|
||||
#define PHP_MODE_INDENT 3
|
||||
|
||||
PHPAPI extern char *optarg;
|
||||
PHPAPI extern int optind;
|
||||
PHPAPI extern char *ap_php_optarg;
|
||||
PHPAPI extern int ap_php_optind;
|
||||
|
||||
|
||||
static int sapi_cgibin_ub_write(const char *str, uint str_length)
|
||||
@@ -266,8 +264,8 @@ int main(int argc, char *argv[])
|
||||
int behavior=PHP_MODE_STANDARD;
|
||||
int no_headers=0;
|
||||
int free_path_translated=0;
|
||||
int orig_optind=optind;
|
||||
char *orig_optarg=optarg;
|
||||
int orig_optind=ap_php_optind;
|
||||
char *orig_optarg=ap_php_optarg;
|
||||
#if SUPPORT_INTERACTIVE
|
||||
int interactive=0;
|
||||
#endif
|
||||
@@ -335,15 +333,15 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
|
||||
}
|
||||
|
||||
if (!cgi) {
|
||||
while ((c=getopt(argc, argv, "c:d:qvisnaeh?vf:"))!=-1) {
|
||||
while ((c=ap_php_getopt(argc, argv, "c:d:qvisnaeh?vf:"))!=-1) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
php_ini_path = strdup(optarg); /* intentional leak */
|
||||
php_ini_path = strdup(ap_php_optarg); /* intentional leak */
|
||||
break;
|
||||
}
|
||||
}
|
||||
optind = orig_optind;
|
||||
optarg = orig_optarg;
|
||||
ap_php_optind = orig_optind;
|
||||
ap_php_optarg = orig_optarg;
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +364,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
|
||||
|
||||
if (!cgi) { /* never execute the arguments if you are a CGI */
|
||||
request_info.php_argv0 = NULL;
|
||||
while ((c = getopt(argc, argv, "c:d:qvisnaeh?vf:")) != -1) {
|
||||
while ((c = ap_php_getopt(argc, argv, "c:d:qvisnaeh?vf:")) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
if (!cgi_started){
|
||||
@@ -379,7 +377,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
|
||||
SG(headers_sent) = 1;
|
||||
}
|
||||
cgi_started=1;
|
||||
SG(request_info).path_translated = estrdup(optarg);
|
||||
SG(request_info).path_translated = estrdup(ap_php_optarg);
|
||||
free_path_translated=1;
|
||||
/* break missing intentionally */
|
||||
case 'q':
|
||||
@@ -437,7 +435,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
|
||||
exit(1);
|
||||
break;
|
||||
case 'd':
|
||||
define_command_line_ini_entry(optarg);
|
||||
define_command_line_ini_entry(ap_php_optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -465,20 +463,20 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
|
||||
|
||||
if (!cgi) {
|
||||
if (!SG(request_info).query_string) {
|
||||
for (i = optind, len = 0; i < argc; i++)
|
||||
for (i = ap_php_optind, len = 0; i < argc; i++)
|
||||
len += strlen(argv[i]) + 1;
|
||||
|
||||
s = malloc(len + 1); /* leak - but only for command line version, so ok */
|
||||
*s = '\0'; /* we are pretending it came from the environment */
|
||||
for (i = optind, len = 0; i < argc; i++) {
|
||||
for (i = ap_php_optind, len = 0; i < argc; i++) {
|
||||
strcat(s, argv[i]);
|
||||
if (i < (argc - 1))
|
||||
strcat(s, "+");
|
||||
}
|
||||
SG(request_info).query_string = s;
|
||||
}
|
||||
if (!SG(request_info).path_translated && argc > optind)
|
||||
SG(request_info).path_translated = argv[optind];
|
||||
if (!SG(request_info).path_translated && argc > ap_php_optind)
|
||||
SG(request_info).path_translated = argv[ap_php_optind];
|
||||
}
|
||||
/* If for some reason the CGI interface is not setting the
|
||||
PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
/* Borrowed from Apache NT Port */
|
||||
|
||||
#if !APACHE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@@ -12,16 +10,16 @@
|
||||
#define OPTERRARG (3)
|
||||
|
||||
|
||||
PHPAPI char *optarg;
|
||||
PHPAPI int optind = 1;
|
||||
static int opterr = 1;
|
||||
static int optopt;
|
||||
PHPAPI char *ap_php_optarg;
|
||||
PHPAPI int ap_php_optind = 1;
|
||||
static int ap_php_opterr = 1;
|
||||
static int ap_php_optopt;
|
||||
|
||||
static int
|
||||
optiserr(int argc, char * const *argv, int oint, const char *optstr,
|
||||
ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr,
|
||||
int optchr, int err)
|
||||
{
|
||||
if (opterr)
|
||||
if (ap_php_opterr)
|
||||
{
|
||||
fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
|
||||
switch(err)
|
||||
@@ -40,22 +38,22 @@ optiserr(int argc, char * const *argv, int oint, const char *optstr,
|
||||
break;
|
||||
}
|
||||
}
|
||||
optopt = argv[oint][optchr];
|
||||
ap_php_optopt = argv[oint][optchr];
|
||||
return('?');
|
||||
}
|
||||
|
||||
PHPAPI int getopt(int argc, char* const *argv, const char *optstr)
|
||||
PHPAPI int ap_php_getopt(int argc, char* const *argv, const char *optstr)
|
||||
{
|
||||
static int optchr = 0;
|
||||
static int dash = 0; /* have already seen the - */
|
||||
|
||||
char *cp;
|
||||
|
||||
if (optind >= argc)
|
||||
if (ap_php_optind >= argc)
|
||||
return(EOF);
|
||||
if (!dash && (argv[optind][0] != '-'))
|
||||
if (!dash && (argv[ap_php_optind][0] != '-'))
|
||||
return(EOF);
|
||||
if (!dash && (argv[optind][0] == '-') && !argv[optind][1])
|
||||
if (!dash && (argv[ap_php_optind][0] == '-') && !argv[ap_php_optind][1])
|
||||
{
|
||||
/*
|
||||
* use to specify stdin. Need to let pgm process this and
|
||||
@@ -63,56 +61,56 @@ PHPAPI int getopt(int argc, char* const *argv, const char *optstr)
|
||||
*/
|
||||
return(EOF);
|
||||
}
|
||||
if ((argv[optind][0] == '-') && (argv[optind][1] == '-'))
|
||||
if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-'))
|
||||
{
|
||||
/* -- indicates end of args */
|
||||
optind++;
|
||||
ap_php_optind++;
|
||||
return(EOF);
|
||||
}
|
||||
if (!dash)
|
||||
{
|
||||
assert((argv[optind][0] == '-') && argv[optind][1]);
|
||||
assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]);
|
||||
dash = 1;
|
||||
optchr = 1;
|
||||
}
|
||||
|
||||
/* Check if the guy tries to do a -: kind of flag */
|
||||
assert(dash);
|
||||
if (argv[optind][optchr] == ':')
|
||||
if (argv[ap_php_optind][optchr] == ':')
|
||||
{
|
||||
dash = 0;
|
||||
optind++;
|
||||
return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRCOLON));
|
||||
ap_php_optind++;
|
||||
return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON));
|
||||
}
|
||||
if (!(cp = strchr(optstr, argv[optind][optchr])))
|
||||
if (!(cp = strchr(optstr, argv[ap_php_optind][optchr])))
|
||||
{
|
||||
int errind = optind;
|
||||
int errind = ap_php_optind;
|
||||
int errchr = optchr;
|
||||
|
||||
if (!argv[optind][optchr+1])
|
||||
if (!argv[ap_php_optind][optchr+1])
|
||||
{
|
||||
dash = 0;
|
||||
optind++;
|
||||
ap_php_optind++;
|
||||
}
|
||||
else
|
||||
optchr++;
|
||||
return(optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
|
||||
return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
|
||||
}
|
||||
if (cp[1] == ':')
|
||||
{
|
||||
dash = 0;
|
||||
optind++;
|
||||
if (optind == argc)
|
||||
return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRARG));
|
||||
optarg = argv[optind++];
|
||||
ap_php_optind++;
|
||||
if (ap_php_optind == argc)
|
||||
return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG));
|
||||
ap_php_optarg = argv[ap_php_optind++];
|
||||
return(*cp);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!argv[optind][optchr+1])
|
||||
if (!argv[ap_php_optind][optchr+1])
|
||||
{
|
||||
dash = 0;
|
||||
optind++;
|
||||
ap_php_optind++;
|
||||
}
|
||||
else
|
||||
optchr++;
|
||||
@@ -122,21 +120,19 @@ PHPAPI int getopt(int argc, char* const *argv, const char *optstr)
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* !APACHE */
|
||||
|
||||
#ifdef TESTGETOPT
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern char *ap_php_optarg;
|
||||
extern int ap_php_optind;
|
||||
int aflg = 0;
|
||||
int bflg = 0;
|
||||
int errflg = 0;
|
||||
char *ofile = NULL;
|
||||
|
||||
while ((c = getopt(argc, argv, "abo:")) != EOF)
|
||||
while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF)
|
||||
switch (c) {
|
||||
case 'a':
|
||||
if (bflg)
|
||||
@@ -151,7 +147,7 @@ int
|
||||
bflg++;
|
||||
break;
|
||||
case 'o':
|
||||
ofile = optarg;
|
||||
ofile = ap_php_optarg;
|
||||
(void)printf("ofile = %s\n", ofile);
|
||||
break;
|
||||
case '?':
|
||||
@@ -162,8 +158,8 @@ int
|
||||
"usage: cmd [-a|-b] [-o <filename>] files...\n");
|
||||
exit (2);
|
||||
}
|
||||
for ( ; optind < argc; optind++)
|
||||
(void)printf("%s\n", argv[optind]);
|
||||
for ( ; ap_php_optind < argc; ap_php_optind++)
|
||||
(void)printf("%s\n", argv[ap_php_optind]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Borrowed from Apache NT Port */
|
||||
#include "php.h"
|
||||
|
||||
PHPAPI extern char *ap_php_optarg;
|
||||
PHPAPI extern int ap_php_optind;
|
||||
extern int ap_php_opterr;
|
||||
extern int ap_php_optopt;
|
||||
|
||||
PHPAPI int ap_php_getopt(int argc, char* const *argv, const char *optstr);
|
||||
@@ -67,18 +67,11 @@
|
||||
#include "zend_highlight.h"
|
||||
#include "zend_indent.h"
|
||||
|
||||
#if WIN32|WINNT || !defined(HAVE_GETOPT)
|
||||
#include "php_getopt.h"
|
||||
#endif
|
||||
|
||||
PHPAPI extern char *php_ini_path;
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
|
||||
(JNIEnv *newJenv, jclass self);
|
||||
|
||||
PHPAPI extern char *optarg;
|
||||
PHPAPI extern int optind;
|
||||
|
||||
typedef struct {
|
||||
JNIEnv *jenv;
|
||||
jobject servlet;
|
||||
|
||||
Reference in New Issue
Block a user