On 24.10.2013 20:44, Maximo, Andre (GE Global Research) wrote:
>
> Hi Bert,
>
>  
>
>   thanks for your prompt reply.  Here is the code:
>
>  
>
> void CVCS::svnURLPath(CString& urlPath, const CString &fullPath)
>
> {
>
>   apr_pool_t *local_pool = svn_pool_create(m_svn_pool);
>
>   const char *url = NULL;
>
>   svn_error_t *err = svn_client_url_from_path2(&url, fullPath,
> m_svn_ctx, m_svn_pool, local_pool);
>
>   if (url != NULL)
>
>     urlPath = CString(url);
>

This is the bug. You must check the value of 'err' before you use the
'url'. Also, you must clear the error before returning from the
function. If svn_client_url_from_path2 failed (i.e., 'err != NULL'),
then 'url' may be completely random, and dereferencing a random pointer
may yield "interesting" results.

You should do something like this, for example:

    svn_error_t *err = svn_client_url_from.....;
    if (err) {
      const char *const message =  svn_error_root_cause(err)->message;
      svn_error_clear(err);   // Otherwise you have a memory leak
      throw std::runtime_exception(message);
    }
    urlPath = CString(url);   // No error, therefore 'url' is valid

//
Of course, how exactly you handle the errors and how you propagate them
up the stack is up to you; the above is just an example, using a
standard exception.

-- Brane

-- 
Branko Čibej | Director of Subversion
WANdisco // Non-Stop Data
e. br...@wandisco.com

Reply via email to