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

Re: skip_uri_scheme question

From: Blair Zajac <blair_at_orcaware.com>
Date: 2007-10-03 15:40:39 CEST

Greg Hudson wrote:
> On Tue, 2007-10-02 at 07:00 -0700, Blair Zajac wrote:
>> In this function:
>>
>> static const char *
>> skip_uri_scheme(const char *path)
>> {
>> apr_size_t j;
>>
>> for (j = 0; path[j]; ++j)
>> if (path[j] == ':' || path[j] == '/')
>> break;
>>
>> if (j > 0 && path[j] == ':' && path[j+1] == '/' && path[j+2] == '/')
>> return path + j + 3;
>>
>>
>> Why do we check for a ':' and a '/' in the for loop to break out early but only
>> return success if that first character is a ':' in the second if?
>
> If the first loop terminates because we've reached the end of the
> string, testing path[j+1] is a possible memory access error. (That may
> or may not have already been clear to you; it's not clear from your
> question which aspect of the function you're finding amiss.)

No, I hope that anyone that works on svn's C code knows to check for the end of
a null terminated string :)

>
> However, we could presumably test for just a ':' in the first loop,
> perhaps using strchr() to knock off a few lines of code.

Thinking about it some more, probably because supposed to not allow a URL of the
form ///://hostname. Without checking for / in the first if statement, it would
allow this URL in the second if statement.

I'll add a comment in the function if this reasoning looks right.

Blair

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Oct 3 15:40:59 2007

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

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