Hi Sara,

> -----Original Message-----
> From: Sara Golemon [mailto:[EMAIL PROTECTED] 
> Sent: Monday, April 03, 2006 9:03 PM
> To: "Dmitry Stogov"
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] RETURN_RT_STRING() and family leakage
> 
> 
> > Your first solution will not work. String passed to
> > ZVAL_RETURN_RT_STRING()
> > may be not allocated by emalloc().
> >
> duplicate should only ever be set to 0 on this (or any of the 
> macros) when 
> the string *is* allocated with emalloc.  Otherwise the 
> enegine would get in 
> trouble freeing it later on.

No. :(
You can use ZVAL_RT_STRING(&fname, "strlen", 0), then call
zend_call_function(&fname) and do not destroy fname.

Thanks. Dmitry.

>  I did just notice that I paste 
> the wrong 
> version into my post though.... it should have been: if 
> (!duplicate && 
> UG(unicode) ...
> 
> #define RETURN_RT_STRING(t, duplicate) \
>  { RETVAL_RT_STRING(t, duplicate); if (!duplicate && 
> UG(unicode)) efree(t); 
> return; }
> 
> > The second solution will work.
> >
> > ZVAL_RETURN_RT_STRINGL(str, len, duplicate) -> 
> > ZVAL_RETURN_RT_STRINGL(str, len, duplicate, auto_free)
> >
> There's one other we came up with:
> 
> Leave existing protos as is, having them assume auto-free 
> when duplicate==0 
> (There is no issue when duplicate==1).
> Create an ad=ditional set of macros: 
> (ZVAL|RETVAL)_RT_STRINGL_NOFREE(str, 
> len) to be used when duplication (for the sake of owning the 
> buffer) is not 
> needed (because it's emalloc'd), but where (str) should not 
> be freeded even 
> in the eventuality that it's converted into a new buffer as unicode 
> contents.
> 
> This gives that edge 10% the ability to reuse (str) after 
> populating it into 
> the zval.  A RETURN variant would be silly here as 
> RETURN_RT_STRING_NOFREE(str) would be guaranteed to leak in 
> unicode mode. 
> (It converts into a new buffer then abandons the old one).
> 
> > 3) It is possible to reuse "duplicate" argument
> > 0 - don't duplicate
> > 1 - duplicate
> > 2 - duplicate and free
> >
> Andrei and I tossed this around last night (and actually it's "don't 
> duplicate and free" since the logic leading to the need for 
> an auto_free 
> assumes that the original string should not have been copied 
> but the unicode 
> conversion demanded that it was).  The trouble with this 
> approach is that 
> it's terribly inconsistent with other ZVAL/RETVAL/RETURN 
> macros in use 
> everywhere else.  e.g. duplicate has always been a binary 
> value, not a 
> trinary one.
> 
> -Sara
> 
> 
> 

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

Reply via email to