httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yann Ylavic <ylavic....@gmail.com>
Subject Re: svn commit: r1533100 - /httpd/httpd/trunk/modules/proxy/proxy_util.c
Date Thu, 17 Oct 2013 15:33:02 GMT
On Thu, Oct 17, 2013 at 5:02 PM, <jim@apache.org> wrote:

> Author: jim
> Date: Thu Oct 17 15:02:04 2013
> New Revision: 1533100
>
> URL: http://svn.apache.org/r1533100
> Log:
> ap_proxy_strncpy should correctly handle src being NULL.
> Actually, apr_cpystrn() should as well...
>
> Modified:
>     httpd/httpd/trunk/modules/proxy/proxy_util.c
>
> Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
> URL:
> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1533100&r1=1533099&r2=1533100&view=diff
>
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
> +++ httpd/httpd/trunk/modules/proxy/proxy_util.c Thu Oct 17 15:02:04 2013
> @@ -93,6 +93,11 @@ PROXY_DECLARE(apr_status_t) ap_proxy_str
>      char *thenil;
>      apr_size_t thelen;
>
> +    /* special case: really  apr_cpystrn should handle src==NULL*/
> +    if (!src && dlen) {
> +        *dst = '\0';
> +        return APR_SUCCESS;
> +    }
>      thenil = apr_cpystrn(dst, src, dlen);
>      thelen = thenil - dst;
>      /* Assume the typical case is smaller copying into bigger
>
>
>
Maybe ap_proxy_strncpy() could aso have no "slow" path with this change :

Index: modules/proxy/proxy_util.c
===================================================================
--- modules/proxy/proxy_util.c    (revision 1533118)
+++ modules/proxy/proxy_util.c    (working copy)
@@ -90,7 +90,6 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY,
 PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src,
                                              apr_size_t dlen)
 {
-    char *thenil;
     apr_size_t thelen;

     /* special case: really  apr_cpystrn should handle src==NULL*/
@@ -98,11 +97,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char
         *dst = '\0';
         return APR_SUCCESS;
     }
-    thenil = apr_cpystrn(dst, src, dlen);
-    thelen = thenil - dst;
-    /* Assume the typical case is smaller copying into bigger
-       so we have a fast return */
-    if ((thelen < dlen-1) || ((strlen(src)) == thelen)) {
+    thelen = apr_cpystrn(dst, src, dlen) - dst;
+    if (thelen < dlen || !src[dlen]) {
         return APR_SUCCESS;
     }
     /* XXX: APR_ENOSPACE would be better */
[EOS]

Regards,
Yann.

Mime
View raw message