diff options
-rw-r--r-- | ChangeLog.TODO | 5 | ||||
-rw-r--r-- | Makefile.in | 5 | ||||
-rw-r--r-- | ext/ereg/ereg.c | 26 | ||||
-rw-r--r-- | ext/standard/datetime.c | 11 | ||||
-rw-r--r-- | ext/standard/reg.c | 26 | ||||
-rw-r--r-- | ext/standard/string.c | 2 | ||||
-rw-r--r-- | main/fopen_wrappers.c | 4 | ||||
-rw-r--r-- | main/php.h | 1 | ||||
-rw-r--r-- | main/php_compat.h | 39 | ||||
-rw-r--r-- | php_compat.c | 230 |
10 files changed, 317 insertions, 32 deletions
diff --git a/ChangeLog.TODO b/ChangeLog.TODO index f4a1e8a347..e503630983 100644 --- a/ChangeLog.TODO +++ b/ChangeLog.TODO @@ -10,11 +10,6 @@ over to PHP4. - added Oracle-OCI8 persistent connections - fixed OCIDefineByName crash. - fixed some NULL-column related problems in OCI8-module. -- avoid stripping double slashes when fopen'ing files (Sascha) -- sql_regcase() change: only apply to alphabetic characters (Sascha) -- add snmprealwalk() (Sascha Schumann) -- fix serious bug in strftime() (Sascha Schumann) -- fix bug in ucwords() (Sascha Schumann) - optimized fgets() and fread() - memory leak in operators.c fixed - socket leak fixed (Sascha Schumann) diff --git a/Makefile.in b/Makefile.in index f363e5eac8..90185c5956 100644 --- a/Makefile.in +++ b/Makefile.in @@ -62,11 +62,11 @@ WARNING_LEVEL = @WARNING_LEVEL@ SOURCE = main.c internal_functions.c snprintf.c php3_sprintf.c \ configuration-parser.c configuration-scanner.c request_info.c \ safe_mode.c fopen-wrappers.c php3_realpath.c alloca.c output.c \ - php_ini.c + php_ini.c php_compat.c OBJS = main.o internal_functions.o snprintf.o php3_sprintf.o \ configuration-parser.o configuration-scanner.o request_info.o \ safe_mode.o fopen-wrappers.o php3_realpath.o alloca.o output.o \ - php_ini.o + php_ini.o php_compat.o FUNCTIONS_SOURCE = functions/apache.c functions/fhttpd.c \ functions/crypt.c functions/db.c functions/dl.c functions/filepro.c \ @@ -184,6 +184,7 @@ indent: clean rm -f *~ functions/*~ .c.o: + @rm -f $@ $(CC) $(CFLAGS) -c $< -o $@ @bn=`echo $@ | sed -e 's#functions/##'`; test -f $@ || \ (test "$@" != "$$bn" && test -f "$$bn" && mv $$bn $@) diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c index 42d36493d6..8b81e82e7f 100644 --- a/ext/ereg/ereg.c +++ b/ext/ereg/ereg.c @@ -537,7 +537,8 @@ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) { pval *string; char *tmp; - register int i; + unsigned char c; + register int i, j; if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) { WRONG_PARAM_COUNT; @@ -547,17 +548,22 @@ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) tmp = (char *) emalloc(string->value.str.len*4+1); - for (i=0; i<string->value.str.len; i++) { - tmp[i*4] = '['; - tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]); - tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]); - tmp[i*4+3]=']'; + for (i=j=0; i<string->value.str.len; i++) { + c = (unsigned char) string->value.str.val[i]; + if(isalpha(c)) { + tmp[j++] = '['; + tmp[j++] = toupper(c); + tmp[j++] = tolower(c); + tmp[j++] = ']'; + } else { + tmp[j++] = c; + } } - tmp[string->value.str.len*4]=0; + tmp[j]=0; + + tmp = erealloc(tmp, j + 1); - return_value->value.str.val = tmp; - return_value->value.str.len = string->value.str.len*4; - return_value->type = IS_STRING; + RETVAL_STRINGL(tmp, j, 0); } /* }}} */ diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index 3c82fe0918..191371a8c2 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -463,6 +463,7 @@ void php3_strftime(INTERNAL_FUNCTION_PARAMETERS) char *format,*buf; time_t timestamp; struct tm *ta; + int max_reallocs = 5; size_t buf_len=64, real_len; switch (ARG_COUNT(ht)) { @@ -495,11 +496,15 @@ void php3_strftime(INTERNAL_FUNCTION_PARAMETERS) while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) { buf_len *= 2; buf = (char *) erealloc(buf, buf_len); + if(!--max_reallocs) break; } - return_value->value.str.val = (char *) erealloc(buf,real_len+1); - return_value->value.str.len = real_len; - return_value->type = IS_STRING; + if(real_len && real_len != buf_len) { + buf = (char *) erealloc(buf,real_len+1); + RETURN_STRINGL(buf, real_len, 0); + } + efree(buf); + RETURN_FALSE; } #endif /* diff --git a/ext/standard/reg.c b/ext/standard/reg.c index 42d36493d6..8b81e82e7f 100644 --- a/ext/standard/reg.c +++ b/ext/standard/reg.c @@ -537,7 +537,8 @@ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) { pval *string; char *tmp; - register int i; + unsigned char c; + register int i, j; if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) { WRONG_PARAM_COUNT; @@ -547,17 +548,22 @@ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) tmp = (char *) emalloc(string->value.str.len*4+1); - for (i=0; i<string->value.str.len; i++) { - tmp[i*4] = '['; - tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]); - tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]); - tmp[i*4+3]=']'; + for (i=j=0; i<string->value.str.len; i++) { + c = (unsigned char) string->value.str.val[i]; + if(isalpha(c)) { + tmp[j++] = '['; + tmp[j++] = toupper(c); + tmp[j++] = tolower(c); + tmp[j++] = ']'; + } else { + tmp[j++] = c; + } } - tmp[string->value.str.len*4]=0; + tmp[j]=0; + + tmp = erealloc(tmp, j + 1); - return_value->value.str.val = tmp; - return_value->value.str.len = string->value.str.len*4; - return_value->type = IS_STRING; + RETVAL_STRINGL(tmp, j, 0); } /* }}} */ diff --git a/ext/standard/string.c b/ext/standard/string.c index 0750aa8734..b9db2614b9 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -972,7 +972,7 @@ void php3_ucwords(INTERNAL_FUNCTION_PARAMETERS) if(*(r+1)){ r++; *r=toupper((unsigned char)*r); - } + } else break; } RETVAL_STRING(arg->value.str.val,1); } diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 206bfa5c76..01a550a958 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -131,6 +131,7 @@ PHPAPI int _php3_check_open_basedir(char *path) local_open_basedir[local_open_basedir_pos--] = 0; } +#if 0 /* Strip double (back)slashes */ if (local_open_basedir_pos > 0) { while (( @@ -144,7 +145,8 @@ PHPAPI int _php3_check_open_basedir(char *path) local_open_basedir[local_open_basedir_pos--] = 0; } } - +#endif + } else { /* Else use the unmodified path */ strcpy(local_open_basedir, PG(open_basedir)); diff --git a/main/php.h b/main/php.h index 06ae5ce7ff..72434c7292 100644 --- a/main/php.h +++ b/main/php.h @@ -510,6 +510,7 @@ extern void phprestart(FILE *input_file); #define XtOffsetOf(s_type,field) XtOffset(s_type*,field) #endif +#include "php_compat.h" #endif diff --git a/main/php_compat.h b/main/php_compat.h new file mode 100644 index 0000000000..2c4aa3e0bf --- /dev/null +++ b/main/php_compat.h @@ -0,0 +1,39 @@ +#ifndef PHP_COMPAT_H +#define PHP_COMPAT_H + +#if (WIN32|WINNT) & HAVE_BINDLIB +#ifndef WINNT +#define WINNT 1 +#endif +#include "arpa/inet.h" +#include "netdb.h" +#include "arpa/nameser.h" +#include "resolv.h" +#endif + +#if !HAVE_FLOCK + +#define LOCK_SH 1 +#define LOCK_EX 2 +#define LOCK_NB 4 +#define LOCK_UN 8 + +extern PHPAPI int flock(int fd, int operation); + +#endif + +#if WIN32|WINNT + +/* These were in win32/flock.h, dunno if they are really needed + (or maybe break something) */ + +#define fsync _commit +#define ftruncate chsize + +#endif /* WIN32|WINNT */ + +#if !HAVE_INET_ATON +extern PHPAPI int inet_aton(const char *, struct in_addr *); +#endif + +#endif diff --git a/php_compat.c b/php_compat.c new file mode 100644 index 0000000000..8a5f973eb1 --- /dev/null +++ b/php_compat.c @@ -0,0 +1,230 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Sascha Schumann <sas@schell.de> | + +----------------------------------------------------------------------+ + + $Id$ + */ + + +#include <errno.h> +#include "php_compat.h" + +#if HAVE_STRUCT_FLOCK +#include <unistd.h> +#include <fcntl.h> +#endif + +#if WIN32|WINNT +#include <windows.h> +#include <io.h> +#endif + +#if !HAVE_FLOCK +PHPAPI int flock(int fd, int operation) +#if HAVE_STRUCT_FLOCK +{ + struct flock flck; + int ret; + + flck.l_start = flck.l_len = 0; + flck.l_whence = SEEK_SET; + + if (operation & LOCK_SH) + flck.l_type = F_RDLCK; + else if (operation & LOCK_EX) + flck.l_type = F_WRLCK; + else if (operation & LOCK_UN) + flck.l_type = F_UNLCK; + else { + errno = EINVAL; + return -1; + } + + ret = fcntl(fd, operation & LOCK_NB ? F_SETLK : F_SETLKW, &flck); + + if (operation & LOCK_NB && ret == -1 && + (errno == EACCES || errno == EAGAIN)) + errno = EWOULDBLOCK; + + if (ret != -1) ret = 0; + + return ret; +} +#elif WIN32|WINNT +/* + * Program: Unix compatibility routines + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 14 September 1996 + * Last Edited: 14 August 1997 + * + * Copyright 1997 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appears in all copies and that both the + * above copyright notice and this permission notice appear in supporting + * documentation, and that the name of the University of Washington not be + * used in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. This software is made available + * "as is", and + * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, + * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN + * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT + * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* DEDICATION + + * This file is dedicated to my dog, Unix, also known as Yun-chan and + * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix + * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after + * a two-month bout with cirrhosis of the liver. + * + * He was a dear friend, and I miss him terribly. + * + * Lift a leg, Yunie. Luv ya forever!!!! + */ +{ + HANDLE hdl = (HANDLE) _get_osfhandle(fd); + DWORD low = 1, high = 0; + OVERLAPPED offset = + {0, 0, 0, 0, NULL}; + if (hdl < 0) + return -1; /* error in file descriptor */ + /* bug for bug compatible with Unix */ + UnlockFileEx(hdl, 0, low, high, &offset); + switch (operation & ~LOCK_NB) { /* translate to LockFileEx() op */ + case LOCK_EX: /* exclusive */ + if (LockFileEx(hdl, LOCKFILE_EXCLUSIVE_LOCK + + ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0), + 0, low, high, &offset)) + return 0; + break; + case LOCK_SH: /* shared */ + if (LockFileEx(hdl, ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0), + 0, low, high, &offset)) + return 0; + break; + case LOCK_UN: /* unlock */ + return 0; /* always succeeds */ + default: /* default */ + break; + } + /* Under Win32 MT library, errno is not a variable but a function call, + * which cannot be assigned to. + */ +#if !(WIN32|WINNT) + errno = EINVAL; /* bad call */ +#endif + return -1; +} +#else +#warning no proper flock support for your site +{ + errno = 0; + return 0; +} +#endif +#endif /* !HAVE_FLOCK */ + +#if !(HAVE_INET_ATON) + +/* + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + */ + +PHPAPI int +inet_aton(const char *cp, struct in_addr *ap) +{ + int dots = 0; + register unsigned long acc = 0, addr = 0; + + do { + register char cc = *cp; + + switch (cc) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + acc = acc * 10 + (cc - '0'); + break; + + case '.': + if (++dots > 3) { + return 0; + } + /* Fall through */ + + case '\0': + if (acc > 255) { + return 0; + } + addr = addr << 8 | acc; + acc = 0; + break; + + default: + return 0; + } + } while (*cp++) ; + + /* Normalize the address */ + if (dots < 3) { + addr <<= 8 * (3 - dots) ; + } + + /* Store it if requested */ + if (ap) { + ap->s_addr = htonl(addr); + } + + return 1; +} + +#endif /* !HAVE_INET_ATON */ |