[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: malformed argument re-use in svn_client_url_from_path2

From: Branko Čibej <brane_at_wandisco.com>
Date: Thu, 24 Oct 2013 22:26:54 +0200

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. brane_at_wandisco.com
Received on 2013-10-24 22:29:21 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.