[PHP-DEV] Re: preg_replace() docs need expliot warning

2003-02-07 Thread pollita
While I'm..*grossly* against the /e switch (or eval()s in general) at
all (and its use with tainted sources even moreso), I realize my whinning
and moaning isn't going to change the fact /e and eval() exist and are used.
But here's a thought...

How about a /E switch to preg_replace which would function like /e except
that it temporarily enables safe_mode.  Similarly eval() could be extended
with a second parameter that does the same.  I realize safe_mode is
generally intended for sysadmins to protect themselves from malicious
content authors, but why not use this functionality at the content level to
protect from malicious clients?

There *might* be a need to have an eval.* version of the safe_mode ini
options to specify how much is (dis)allowed when in eval-safe_mode.  I
havn't thought through the implications of doing this, but it seems worth
exploring.

-Pollita

Cross-Posting to php-dev


"James E. Flemer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> Just one more example.  Even when using double quotes, it
> is possible to execute code:
>
>$a = '___! ${`rm -rf /tmp/sess_*`} !___';
>   $b = preg_replace("/!(.*)!/e", "print(\"\\1\");", $a);
> ?>
>
> Again, assume $a comes from a tainted source.
>
> -James
>
> On Mon, 3 Feb 2003, James E. Flemer wrote:
>
> > A warning about preg_replace() command needs to be added to
> > the docs page for this command.  The preg_replace() command
> > can use the "/e" modifier to have the "replacement" be
> > eval()d by PHP, just like perl.
> >
> > There is a high potential for exploitable PHP code if a
> > programmer uses the /e modifier and does not use quotes
> > around the back references (backrefs).  Without quotes,
> > arbitrary commands may be executed by using the backtick
> > operator.  Other commands may be executed as well, but are
> > more difficult, since addslashes() prevents the characters
> > ['"\\\0] from being used.
> >
> > An clear and explicit warning should be added to the doc
> > page for preg_replace, indicating the backrefs must always
> > be quoted.  Single quotes are preferable, since double
> > quotes allow variable expansion.
> >
> > See the messages below for examples of how this may be
> > exploited.  (Assume that $a comes from an untrusted source,
> > i.e. a get/post/cookie/header variable.)
> >
> > -James
> >
> > -- Forwarded message --
> > Date: Mon, 3 Feb 2003 01:04:23 -0500 (EST)
> > From: James E. Flemer <[EMAIL PROTECTED]>
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP-DEV] preg_replace oddity [exploitable]
> >
> > I found a more evil example:
> >
> >  >   $a = "___! `rm -rf /tmp/sess_*` !___";
> >   $b = preg_replace("/!(.*)!/e", "print(\\1);", $a);
> > ?>
> >
> > This happily executes "rm -rf /tmp/sess_*".  I will not
> > give out more examples, but if one examines the code for
> > addslashes() it is quite obvious what you can an cannot do
> > here.  Thus it is clearly a Bad Thing for someone to use
> > preg_replace with the /e modifier and not use quotes around
> > the \\n or $n backrefs.
> >
> > The docs should be updated to include a very noticeable
> > warning about this hole.  I am contemplating possible
> > solutions for this problem...
> >
> > Also as a side note, it does not seem to be possible to use
> > 'echo' as part of the expression, print must be used.  (Yes
> > I know why, just pointing it out.)
> >
> > -James
> >
> >
> > On Thu, 30 Jan 2003, James E. Flemer wrote:
> >
> > > Can someone explain what is going on here:
> > >
> > > --- foo.php ---
> > >  > >   $a = "___! 52); echo(42 !___";
> > >   $b = preg_replace("/!(.*)!/e", "print(\\1);", $a);
> > >   print("\n---\na: $a\nb: $b\n");
> > > ?>
> > > --- end ---
> > > --- output ---
> > > 52
> > > ---
> > > a: ___! 52); echo(42 !___
> > > b: ___1___
> > > --- end ---
> > >
> > > I understand that one is supposed to use single quotes
> > > around the \\1 in the above preg_replace.  But what happens
> > > when they do not?  Clearly the echo(42); is not executed,
> > > and it is not printed by print().  Even more interesting is
> > > if you put something like echo(\"42 in $a, then you get a
> > > bunch of errors including:
> > >   Fatal error - Failed evaluating code:
> > >   print( 52); echo(\"42 );
> > >
> > > It seems like preg_replace() is doing some strange things,
> > > and might be something that could be exploitable if a
> > > remote user can supply the first argument, and the second
> > > argument does not enclose \\n options.
> > >
> > > -James
> >
> >
> >
>




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] [PATCH] Fix to dns_get_record

2002-11-22 Thread Pollita
Thanks for your modifications to dns_get_record Marcus, but an extra
change or two needs to be throw in to get it working just right.  Here's a
tiny patch to avoid inserting random values as subarrays (leading to a
segfault) and properly dispose of resolv resources between queries.

Trouble is, the function as I had it WOULDN'T get unexpected records (see
"this shouldn't happen" comment), but your changes made that a possibility
and allowed php_parserr to return without ever properly setting *subarray.

It dosen't help that the "unexpected" condition wasn't dealing with it's
potentiality right to begin with... :)

-Pollita


Index: dns.c
===
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.45
diff -u -r1.45 dns.c
--- dns.c   19 Nov 2002 02:34:13 -  1.45
+++ dns.c   22 Nov 2002 22:14:34 -
@@ -331,8 +331,9 @@
GETLONG(ttl, cp);
GETSHORT(dlen, cp);
if (type_to_fetch != T_ANY && type != type_to_fetch) {
-   /* Should never actually occour */
-   return NULL;
+   *subarray = NULL;
+   cp += dlen;
+   return cp;
}

if (!store) {
@@ -576,6 +577,7 @@

zend_hash_next_index_insert(HASH_OF(return_value), (void
*)&subarray[current_subarray], sizeof(zval *), NULL);
current_subarray++;
}
+   res_nclose(&res);
}
}




Index: dns.c
===
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.45
diff -u -r1.45 dns.c
--- dns.c   19 Nov 2002 02:34:13 -  1.45
+++ dns.c   22 Nov 2002 22:14:34 -
@@ -331,8 +331,9 @@
GETLONG(ttl, cp);
GETSHORT(dlen, cp);
if (type_to_fetch != T_ANY && type != type_to_fetch) {
-   /* Should never actually occour */
-   return NULL;
+   *subarray = NULL;
+   cp += dlen;
+   return cp;
}
 
if (!store) {
@@ -576,6 +577,7 @@

zend_hash_next_index_insert(HASH_OF(return_value), (void 
*)&subarray[current_subarray], sizeof(zval *), NULL);
current_subarray++;
}
+   res_nclose(&res);
}
}
 


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DEV] [PATCH] php4/configure.in.patch & php4/ext/standard/dns_get_record.patch

2002-11-17 Thread Pollita
This is to update configure.in so that configure checks for the existence
of res_nmkquery, res_nsend, and dn_expand which are needed by
dns_getrecord(). which is appearantly going to be dns_get_record
now

Speaking of which I've also attached dns_get_record.patch.txt to update my
previous patch which introduced the function as dns_getrecord

Pasting as text as well because of recent not-always-attaching issues in
my mail client.


php4/configure.in.patch


Index: configure.in
===
RCS file: /repository/php4/configure.in,v
retrieving revision 1.401
diff -u -r1.401 configure.in
--- configure.in15 Nov 2002 15:35:11 -  1.401
+++ configure.in17 Nov 2002 21:24:16 -
@@ -292,15 +292,17 @@
 AC_CHECK_LIB(m, sin)

 dnl Check for resolver routines.
-dnl Need to check for both res_search and __res_search
+dnl Need to check for both res_search and __res_search, as well as
res_nmkquery and res_nsend
 dnl in -lc, -lbind, -lresolv and -lsocket
 PHP_CHECK_FUNC(res_search, resolv, bind, socket)
+PHP_CHECK_FUNC(res_nmkquery, resolv, bind, socket)
+PHP_CHECK_FUNC(res_nsend, resolv, bind, socket)

-dnl Check for inet_aton and dn_skipname
+dnl Check for inet_aton, dn_skipname and dn_expand
 dnl in -lc, -lbind and -lresolv
 PHP_CHECK_FUNC(inet_aton, resolv, bind)
 PHP_CHECK_FUNC(dn_skipname, resolv, bind)
-
+PHP_CHECK_FUNC(dn_expand, resolv, bind)

 dnl Then headers.
 dnl
-







php4/ext/standard/dns_get_record.patch



Index: basic_functions.c
===
RCS file: /repository/php4/ext/standard/basic_functions.c,v
retrieving revision 1.543
diff -u -r1.543 basic_functions.c
--- basic_functions.c   8 Nov 2002 15:49:32 -   1.543
+++ basic_functions.c   17 Nov 2002 20:28:34 -
@@ -17,7 +17,7 @@
+--+
  */

-/* $Id: basic_functions.c,v 1.543 2002/11/08 15:49:32 sterling Exp $ */
+/* $Id: basic_functions.c,v 1.543 2002/11/16 13:18:21 pollita Exp $ */

 #include "php.h"
 #include "php_streams.h"
@@ -440,6 +440,7 @@

 #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) ||
defined(NETWARE))
PHP_FE(checkdnsrr, 
 NULL)
+PHP_FE(dns_get_record,third_and_rest_force_ref)
PHP_FE(getmxrr,second_and_third_args_force_ref)
 #endif

@@ -1021,6 +1022,7 @@
register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
register_string_constants(INIT_FUNC_ARGS_PASSTHRU);

+   PHP_MINIT(dns) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(regex) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(file) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(pack) (INIT_FUNC_ARGS_PASSTHRU);
Index: dns.c
===
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.44
diff -u -r1.44 dns.c
--- dns.c   18 Oct 2002 22:08:23 -  1.44
+++ dns.c   17 Nov 2002 20:28:34 -
@@ -16,7 +16,7 @@
+--+
  */

-/* $Id: dns.c,v 1.44 2002/10/18 22:08:23 sniper Exp $ */
+/* $Id: dns.c,v 1.44 2002/11/16 17:43:41 pollita Exp $ */

 /* {{{ includes
  */
@@ -71,6 +71,13 @@
 #include "dns.h"
 /* }}} */

+#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
+typedef union {
+   HEADER qb1;
+   u_char qb2[65536];
+} querybuf;
+#endif
+
 static char *php_gethostbyaddr(char *ip);
 static char *php_gethostbyname(char *name);

@@ -276,6 +283,257 @@
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN  256
 #endif /* MAXHOSTNAMELEN */
+
+#ifndef MAXRESOURCERECORDS
+#define MAXRESOURCERECORDS 64
+#endif /* MAXRESOURCERECORDS */
+
+PHP_MINIT_FUNCTION(dns) {
+   REGISTER_LONG_CONSTANT("DNS_ANY", T_ANY, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_A", T_A, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_MX", T_MX, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_CNAME", T_CNAME, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_NS", T_NS, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_TXT", T_TXT, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_PTR", T_PTR, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_SOA", T_SOA, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_HINFO", T_HINFO, CONST_CS | CONST_PERSISTENT);
+}
+
+/* {{{ php_parserr
+ */
+u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, zval
**subarray) {
+   u_short type, class, dlen;
+   u_long ttl;
+   l

[PHP-DEV] dns_getrecord.patch -- trying again

2002-11-17 Thread Pollita
I'll put the text in the body of my message AND attach with .txt this
time.



Index: basic_functions.c
===
RCS file: /repository/php4/ext/standard/basic_functions.c,v
retrieving revision 1.543
diff -u -r1.543 basic_functions.c
--- basic_functions.c   8 Nov 2002 15:49:32 -   1.543
+++ basic_functions.c   17 Nov 2002 20:28:34 -
@@ -17,7 +17,7 @@
+--+
  */

-/* $Id: basic_functions.c,v 1.543 2002/11/08 15:49:32 sterling Exp $ */
+/* $Id: basic_functions.c,v 1.543 2002/11/16 13:18:21 pollita Exp $ */

 #include "php.h"
 #include "php_streams.h"
@@ -440,6 +440,7 @@

 #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) ||
defined(NETWARE))
PHP_FE(checkdnsrr, 
 NULL)
+PHP_FE(dns_getrecord,third_and_rest_force_ref)
PHP_FE(getmxrr,second_and_third_args_force_ref)
 #endif

@@ -1021,6 +1022,7 @@
register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
register_string_constants(INIT_FUNC_ARGS_PASSTHRU);

+   PHP_MINIT(dns) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(regex) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(file) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(pack) (INIT_FUNC_ARGS_PASSTHRU);
Index: dns.c
===
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.44
diff -u -r1.44 dns.c
--- dns.c   18 Oct 2002 22:08:23 -  1.44
+++ dns.c   17 Nov 2002 20:28:34 -
@@ -16,7 +16,7 @@
+--+
  */

-/* $Id: dns.c,v 1.44 2002/10/18 22:08:23 sniper Exp $ */
+/* $Id: dns.c,v 1.44 2002/11/16 17:43:41 pollita Exp $ */

 /* {{{ includes
  */
@@ -71,6 +71,13 @@
 #include "dns.h"
 /* }}} */

+#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
+typedef union {
+   HEADER qb1;
+   u_char qb2[65536];
+} querybuf;
+#endif
+
 static char *php_gethostbyaddr(char *ip);
 static char *php_gethostbyname(char *name);

@@ -276,6 +283,257 @@
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN  256
 #endif /* MAXHOSTNAMELEN */
+
+#ifndef MAXRESOURCERECORDS
+#define MAXRESOURCERECORDS 64
+#endif /* MAXRESOURCERECORDS */
+
+PHP_MINIT_FUNCTION(dns) {
+   REGISTER_LONG_CONSTANT("DNS_ANY", T_ANY, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_A", T_A, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_MX", T_MX, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_CNAME", T_CNAME, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_NS", T_NS, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_TXT", T_TXT, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_PTR", T_PTR, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_SOA", T_SOA, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT("DNS_HINFO", T_HINFO, CONST_CS | CONST_PERSISTENT);
+}
+
+/* {{{ php_parserr
+ */
+u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, zval
**subarray) {
+   u_short type, class, dlen;
+   u_long ttl;
+   long n, i;
+   char name[MAXHOSTNAMELEN];
+
+   n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+
+   GETSHORT(type, cp);
+   GETSHORT(class, cp);
+   GETLONG(ttl, cp);
+   GETSHORT(dlen, cp);
+   if (type_to_fetch != T_ANY && type != type_to_fetch) {
+   /* Should never actually occour */
+   cp += dlen;
+   return NULL;
+   }
+
+   MAKE_STD_ZVAL(*subarray);
+   if (array_init(*subarray) != SUCCESS) {
+   return NULL;
+   }
+   add_assoc_string(*subarray, "host", name, 1);
+
+   switch (type) {
+   case T_A:
+   add_assoc_string(*subarray, "type", "A", 1);
+   sprintf(name, "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]);
+   add_assoc_string(*subarray, "ip", name, 1);
+   cp += dlen;
+   break;
+   case T_MX:
+   add_assoc_string(*subarray, "type", "MX", 1);
+   GETSHORT(n, cp);
+   add_assoc_long(*subarray, "pri", n);
+   case T_CNAME:
+   if (type == T_CNAME)
+   add_assoc_string(*subarray, "type", "CNAME", 1);
+   ca

Re: Oops: [PHP-DEV] Updated getanyrr.patch, now dns_getrecord.patch

2002-11-17 Thread Pollita
*sigh*  shoot me billy


> On Sun, 17 Nov 2002, Pollita wrote:
>
>> Ooops, after running the diff, I made a last minute change, adding
>> RETURN_TRUE; to the end of the function and was too lazy to rerun the
>> diff forgetting that the lines-to-insert count would go up
>>
>> Here's a version of that diff that'll actually patch right:
>
> Hmm, empty attachments are indeed easy to apply :-) I think you forgot
> it.
>
> Derick
>
> --
>
> ---
>  Derick Rethans
> http://derickrethans.nl/  JDI Media Solutions
> --[ if you hold a unix shell to your ear, do you hear the c?
> ]-




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php


Oops: [PHP-DEV] Updated getanyrr.patch, now dns_getrecord.patch

2002-11-17 Thread Pollita
Ooops, after running the diff, I made a last minute change, adding
RETURN_TRUE; to the end of the function and was too lazy to rerun the diff
forgetting that the lines-to-insert count would go up

Here's a version of that diff that'll actually patch right:


> Attached is dns_getrecord.patch, previously known as getanyrr.patch for
> introducing a new function.  I've made the changes suggested including:
>
> * Rename function
>
> * Add whitespace in argument list of functions called
>
> * Change parameter two from string to int, use defined constants instead
> DNS_ANY DNS_A DNS_MX DNS_NS DNS_CNAME DNS_PTR DNS_TXT DNS_SOA DNS_HINFO
>
> * Caught the fact I wasn't checking for a user supplied type of "HINFO"
> *whoops*
>
> What I unfortunately don't know how to do is update the ./configure
> process to check for existance of: res_nmkquery, res_nsend, and
> dn_expand.
>  At the moment all I can do is rely on the fact that libresolv *is*
> being
> tested for, and that it should contain these functions.  If someone
> could point me to documentation on updating that process I'd appreciate
> it, otherwise I'll go back to searching for it.
>
> -Pollita




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DEV] Updated getanyrr.patch, now dns_getrecord.patch

2002-11-17 Thread Pollita
Attached is dns_getrecord.patch, previously known as getanyrr.patch for
introducing a new function.  I've made the changes suggested including:

* Rename function

* Add whitespace in argument list of functions called

* Change parameter two from string to int, use defined constants instead
DNS_ANY DNS_A DNS_MX DNS_NS DNS_CNAME DNS_PTR DNS_TXT DNS_SOA DNS_HINFO

* Caught the fact I wasn't checking for a user supplied type of "HINFO"
*whoops*

What I unfortunately don't know how to do is update the ./configure
process to check for existance of: res_nmkquery, res_nsend, and dn_expand.
 At the moment all I can do is rely on the fact that libresolv *is* being
tested for, and that it should contain these functions.  If someone could
point me to documentation on updating that process I'd appreciate it,
otherwise I'll go back to searching for it.

-Pollita



cvs -z3 -q diff basic_functions.c dns.c dns.h (in directory S:\php4-HEAD\ext\standard)
Index: basic_functions.c
===
RCS file: /repository/php4/ext/standard/basic_functions.c,v
retrieving revision 1.543
diff -u -r1.543 basic_functions.c
--- basic_functions.c   8 Nov 2002 15:49:32 -   1.543
+++ basic_functions.c   17 Nov 2002 00:15:19 -
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: basic_functions.c,v 1.543 2002/11/08 15:49:32 sterling Exp $ */
+/* $Id: basic_functions.c,v 1.543 2002/11/16 13:18:21 pollita Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -440,6 +440,7 @@
 
 #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || defined(NETWARE))
PHP_FE(checkdnsrr, 
 NULL)
+PHP_FE(dns_getrecord,third_and_rest_force_ref)
PHP_FE(getmxrr,second_and_third_args_force_ref)
 #endif
 
Index: dns.c
===
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.44
diff -u -r1.44 dns.c
--- dns.c   18 Oct 2002 22:08:23 -  1.44
+++ dns.c   17 Nov 2002 17:49:37 -
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: dns.c,v 1.44 2002/10/18 22:08:23 sniper Exp $ */
+/* $Id: dns.c,v 1.44 2002/11/16 17:43:41 pollita Exp $ */
 
 /* {{{ includes
  */
@@ -71,6 +71,13 @@
 #include "dns.h"
 /* }}} */
 
+#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
+typedef union {
+   HEADER qb1;
+   u_char qb2[65536];
+} querybuf;
+#endif
+
 static char *php_gethostbyaddr(char *ip);
 static char *php_gethostbyname(char *name);
 
@@ -276,6 +283,255 @@
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN  256
 #endif /* MAXHOSTNAMELEN */
+
+#ifndef MAXRESOURCERECORDS
+#define MAXRESOURCERECORDS 64
+#endif /* MAXRESOURCERECORDS */
+
+REGISTER_LONG_CONSTANT("DNS_ANY", T_ANY, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_A", T_A, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_MX", T_MX, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_CNAME", T_CNAME, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_NS", T_NS, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_TXT", T_TXT, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_PTR", T_PTR, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_SOA", T_SOA, CONST_CS | CONST_PERSISTENT);
+REGISTER_LONG_CONSTANT("DNS_HINFO", T_HINFO, CONST_CS | CONST_PERSISTENT);
+
+/* {{{ php_parserr
+ */
+u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, zval **subarray) 
+{
+   u_short type, class, dlen;
+   u_long ttl;
+   long n, i;
+   char name[MAXHOSTNAMELEN];
+
+   n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+
+   GETSHORT(type, cp);
+   GETSHORT(class, cp);
+   GETLONG(ttl, cp);
+   GETSHORT(dlen, cp);
+   if (type_to_fetch != T_ANY && type != type_to_fetch) {
+   /* Should never actually occour */
+   cp += dlen;
+   return NULL;
+   }
+
+   MAKE_STD_ZVAL(*subarray);
+   if (array_init(*subarray) != SUCCESS) {
+   return NULL;
+   }
+   add_assoc_string(*subarray, "host", name, 1);
+
+   switch (type) {
+   case T_A:
+   add_assoc_string(*subarray, "type", "A", 1);
+   sprintf(name, "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]);
+   add_assoc_string(*subarray, "ip", name, 1);
+   c

Re: [PHP-DEV] ext/standard/tests/math/log.phpt coredump on Tru64

2002-11-16 Thread Pollita
log(0) in any base (except 0, which would be silly) is an undefined
number.  the libc log() function will return an exceedingly small number
to avoid causing widepsread panic when log(0) is attempted
(-1.7976931348623E+308 shown below).  The test function for log:

$x2 = (int) pow($base, log($x, $base));

attempts to check that $x2 is close to $x, but since log(0,*) will return
an excessively small number, pow() winds up choking.

Suggest: $x2 = (int) log(pow($x,base),$base); instead.

-Pollita

P.S. example below using log in base 1 is also nonsensical... only
log(1,1) is a valid use of log with a base parameter of 1, any other value
results in "undefined"

> Hi,
>
> php4-STABLE-200211152030 dumps core on Tru64/Alpha with
> ext/standard/tests/math/log.phpt:
>
>  EXPECTED OUTPUT
> On failure, please mail result to [EMAIL PROTECTED]
> 200
> 50
> 50
> 50
> 50
> 50
> 50
> 50
> 50
> 50
>  ACTUAL OUTPUT
> On failure, please mail result to [EMAIL PROTECTED]
> 200
>  FAILED
>
> Looking which values it doesn't like:
>
> # sapi/cli/php -r 'echo log(0, 2),"\n";'
> Floating point exception (core dumped)
> # sapi/cli/php -r 'echo log(0, 3),"\n";'
> -1.6363308087894E+308
> # sapi/cli/php -r 'echo log(0, 10),"\n";'
> -7.8072820862606E+307
> # sapi/cli/php -r 'echo log(0, 1),"\n";'
> Floating point exception (core dumped)
> # sapi/cli/php -r 'echo log(0),"\n";'
> -1.7976931348623E+308
>
> Regards...
>   Michael
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] [PATH] update to earlier proposed patch for getanyrr() function addition

2002-11-16 Thread Pollita
Per corrections suggested by [EMAIL PROTECTED], attached is a revised pacth to
ext/standard/dns.c for addition of getanyrr() function.


--- dns.c   Sat Nov 16 13:31:51 2002
+++ dns.c   Sat Nov 16 15:04:07 2002
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: dns.c,v 1.44 2002/10/18 22:08:23 sniper Exp $ */
+/* $Id: dns.c,v 1.44 2002/11/16 14:51:58 pollita Exp $ */
 
 /* {{{ includes
  */
@@ -276,6 +276,252 @@
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN  256
 #endif /* MAXHOSTNAMELEN */
+
+#ifndef MAXRESOURCERECORDS
+#define MAXRESOURCERECORDS 64
+#endif /* MAXRESOURCERECORDS */
+
+/* {{{ php_parserr
+ */
+u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, zval **subarray) 
+{
+   u_short type, class, dlen;
+   u_long ttl;
+   long n, i;
+   char name[MAXHOSTNAMELEN];
+
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof name) - 2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+
+   GETSHORT(type,cp);
+   GETSHORT(class,cp);
+   GETLONG(ttl,cp);
+   GETSHORT(dlen,cp);
+   if (type_to_fetch != T_ANY && type != type_to_fetch) {
+   /* Should never actually occour */
+   cp += dlen;
+   return NULL;
+   }
+
+   MAKE_STD_ZVAL(*subarray);
+   if (array_init(*subarray) != SUCCESS) {
+   return NULL;
+   }
+   add_assoc_string(*subarray,"host",name,1);
+
+   switch (type) {
+   case T_A:
+   add_assoc_string(*subarray,"type","A",1);
+   sprintf(name,"%d.%d.%d.%d",cp[0],cp[1],cp[2],cp[3]);
+   add_assoc_string(*subarray,"ip",name,1);
+   cp += dlen;
+   break;
+   case T_MX:
+   add_assoc_string(*subarray,"type","MX",1);
+   GETSHORT(n,cp);
+   add_assoc_long(*subarray,"pri",n);
+   case T_CNAME:
+   if (type == T_CNAME)
+   add_assoc_string(*subarray,"type","CNAME",1);
+   case T_NS:
+   if (type == T_NS)
+   add_assoc_string(*subarray,"type","NS",1);
+   case T_PTR:
+   if (type == T_PTR)
+   add_assoc_string(*subarray,"type","PTR",1);
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof 
+name) - 2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+   add_assoc_string(*subarray,"target",name,1);
+   break;
+   case T_HINFO:
+   /* See RFC 1010 for values */
+   GETSHORT(n,cp);
+   add_assoc_long(*subarray,"cpu",n);
+   GETSHORT(n,cp);
+   add_assoc_long(*subarray,"os",n);
+   break;
+   case T_TXT:
+   add_assoc_string(*subarray,"type","TXT",1);
+   n = cp[0];
+   for(i=1; i<=n; i++)
+   name[i-1] = cp[i];
+   name[i-1] = '\0';
+   cp += dlen;
+   add_assoc_string(*subarray,"txt",name,1);
+   break;
+   case T_SOA:
+   add_assoc_string(*subarray,"type","SOA",1);
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof 
+name) -2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+   add_assoc_string(*subarray,"mname",name,1);
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof 
+name) -2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+   add_assoc_string(*subarray,"rname",name,1);
+   GETLONG(n,cp);
+   add_assoc_long(*subarray,"serial",n);
+   GETLONG(n,cp);
+   add_assoc_long(*subarray,"refresh",n);
+   GETLONG(n,cp);
+   add_assoc_long(*subarray,"retry",n);
+   GETLONG(n,cp);
+   add_assoc_long(*subarray,"expire

[PHP-DEV] [PATCH]s New Function getanyrr() proposal

2002-11-16 Thread Pollita
The three attached patch files (to be applied in ext/standard/ ) introduce
a new function: getanyrr().  Where the existing getmxrr() will retrieve MX
records for a given host, getanyrr() will return all standard INET DNS
Resource Records.

proto:
  array getanyrr(string hostname [, string type[, array authns, array
addtl]])

"Type" is optional and can be any of "ANY", "A", "MX", "CNAME", "NS",
"TXT", "SOA", "HINFO", or "PTR".  "ANY" is default.

getanyrr returns an index array of associative arrays.  Each associative
array contains 'host', 'type', 'class', 'ttl', and one or more additional
records depending on type.

The third and fourth arguments are pass-by-ref arrays with the same
structure as the function return argument.  "authns" contains a list of
authoritative name servers, while "addtl" contains additional relevant
records (typically A records for the name servers).

Further documentation to be submitted to PHP-DOC when and if attached
patches are accepted and committed to CVS.

basic_functions.cPatch against r1.543
dns.cPatch against r1.44
dns.hPatch against r1.11


--- basic_functions.c   Sat Nov 16 13:35:31 2002
+++ basic_functions.c   Sat Nov 16 13:41:53 2002
@@ -17,7 +17,7 @@
+------+
  */
 
-/* $Id: basic_functions.c,v 1.543 2002/11/08 15:49:32 sterling Exp $ */
+/* $Id: basic_functions.c,v 1.543 2002/11/16 13:18:21 pollita Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -440,6 +440,7 @@
 
 #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || defined(NETWARE))
PHP_FE(checkdnsrr, 
 NULL)
+PHP_FE(getanyrr,third_and_rest_force_ref)
PHP_FE(getmxrr,second_and_third_args_force_ref)
 #endif
 
--- dns.h   Sat Nov 16 13:33:06 2002
+++ dns.h   Sat Nov 16 13:38:33 2002
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: dns.h,v 1.11 2002/02/28 08:26:44 sebastian Exp $ */
+/* $Id: dns.h,v 1.12 2002/11/16 13:38:33 pollita Exp $ */
 
 #ifndef DNS_H
 #define DNS_H
@@ -27,7 +27,14 @@
 
 #if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
 PHP_FUNCTION(checkdnsrr);
+PHP_FUNCTION(getanyrr);
 PHP_FUNCTION(getmxrr);
+
+typedef union {
+HEADER qb1;
+u_char qb2[65536];
+} querybuf;
+
 #endif
 
 #ifndef INT16SZ
--- dns.c   Sat Nov 16 13:31:51 2002
+++ dns.c   Sat Nov 16 13:45:25 2002
@@ -277,6 +277,244 @@
 #define MAXHOSTNAMELEN  256
 #endif /* MAXHOSTNAMELEN */
 
+#ifndef MAXRESOURCERECORDS
+#define MAXRESOURCERECORDS 64
+#endif /* MAXRESOURCERECORDS */
+
+/* {{{ php_parserr
+ */
+u_char *php_parserr(u_char *cp, querybuf *answer, int typeToFetch, zval **subarray) {
+   u_short type,class,dlen;
+   u_long ttl;
+   long n,i;
+   char name[MAXHOSTNAMELEN];
+
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof name) - 2);
+   if (n < 0) {
+   return NULL;
+   }
+   cp += n;
+
+   GETSHORT(type,cp);
+   GETSHORT(class,cp);
+   GETLONG(ttl,cp);
+   GETSHORT(dlen,cp);
+   if (typeToFetch != T_ANY && type != typeToFetch) {
+   /* Should never actually occour */
+   cp += dlen;
+   return NULL;
+   }
+
+   MAKE_STD_ZVAL(*subarray);
+   if (array_init(*subarray) != SUCCESS) {
+   return NULL;
+   }
+   add_assoc_string(*subarray,"host",name,1);
+
+   switch (type) {
+   case T_A:
+   add_assoc_string(*subarray,"type","A",1);
+   sprintf(name,"%d.%d.%d.%d",cp[0],cp[1],cp[2],cp[3]);
+   add_assoc_string(*subarray,"ip",name,1);
+   cp += dlen;
+   break;
+   case T_MX:
+   add_assoc_string(*subarray,"type","MX",1);
+   GETSHORT(n,cp);
+   add_assoc_long(*subarray,"pri",n);
+   case T_CNAME:
+   if (type == T_CNAME)
+   add_assoc_string(*subarray,"type","CNAME",1);
+   case T_NS:
+   if (type == T_NS)
+   add_assoc_string(*subarray,"type","NS",1);
+   case T_PTR:
+   if (type == T_PTR)
+   add_assoc_string(*subarray,"type","PTR",1);
+   n = dn_expand(answer->qb2,answer->qb2+65536,cp,name,(sizeof 
+nam

Re: [PHP-DEV] [PATCH] Proposed modification to log() in ext/standard/math.c

2002-11-10 Thread Pollita
Apologies... I've made a new .patch file relative to revision 1.93 of
math.c in the CVS tree with modifications per instructions in
CODING_STANDARDS.  Hope this meets with approval.


> On Sun, 10 Nov 2002, Pollita wrote:
>
>> I would like to offer the attached minor patch (relative to php-4.2.3)
>> to ext/standard/math.c to extend the functionality of log() to support
>> arbitrary bases.
>
> Please provide a unified diff (diff -u) against the latest CVS version.
> Also, please stick to the coding standards as described in the
> CODING_STANDARDS file.
>
> regards,
> Derick
>
> --
>
> ---
>  Derick Rethans
> http://derickrethans.nl/  JDI Media Solutions
> --[ if you hold a unix shell to your ear, do you hear the c?
> ]-



--- math.c  Sun Nov 10 14:34:19 2002
+++ math-smg.c  Sun Nov 10 14:39:39 2002
@@ -525,13 +525,27 @@
 
 PHP_FUNCTION(log)
 {
-   zval **num;
+   zval **num,**Zbase;
+   double base;
+   double denom=1.0;
 
-   if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
+   if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_ex(2, 
+&num, &Zbase) == FAILURE) {
WRONG_PARAM_COUNT;
}
+   /* If second parameter "base" is specified, use it, otherwise accept e */
+if (ZEND_NUM_ARGS() > 1) {
+convert_to_double_ex(Zbase);
+base = Z_DVAL_PP(Zbase);
+if (base > 0.0) denom = log(base);
+else{
+   /* A base of <= 0 is non-sensical */
+php_error(E_WARNING,"base parameter of log() 
+must be greater than 0");
+RETURN_FALSE;
+}
+}
+
convert_to_double_ex(num);
-   Z_DVAL_P(return_value) = log(Z_DVAL_PP(num));
+   Z_DVAL_P(return_value) = log(Z_DVAL_PP(num)) / denom;
Z_TYPE_P(return_value) = IS_DOUBLE;
 }
 




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DEV] [PATCH] Proposed modification to log() in ext/standard/math.c

2002-11-10 Thread Pollita
I would like to offer the attached minor patch (relative to php-4.2.3) to
ext/standard/math.c to extend the functionality of log() to support
arbitrary bases.

The patch would extend:
  float log(float number)
to:
  float log(float number[,float base])

With no base parameter specified it would function as before returning the
logarithm with respect to base e.  Specifying a base would allow it to
return a logarithm in any other positive base.

For Example:
  print log(32,2);   // Would output "5"
  print log(81,3);   // Would output "4"
while:
  print log(M_E);// Would still output 1 as normal

I was told on Freenode/#OPN that this was the place to submit suggested
patches.



524,526c524,527
<   zval **num;
< 
<   if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
---
>   zval **num,**Zbase;
>   double base;
>   double denom=1.0;
>   if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_ex(2, 
>&num,  &Zbase) == FAILURE) {
528a530,538
>   if (ZEND_NUM_ARGS() > 1) {
>   convert_to_double_ex(Zbase);
>   base = Z_DVAL_PP(Zbase);
>   if (base > 0.0) denom = log(base);
>   else{
>   php_error(E_WARNING,"base parameter of log() 
>must be greater than 0");
>   RETURN_FALSE;
>   }
>   }
530c540
<   Z_DVAL_P(return_value) = log(Z_DVAL_PP(num));
---
>   Z_DVAL_P(return_value) = log(Z_DVAL_PP(num))/denom;


-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php