git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/5] gitweb: Split validate_input into validate_pathname and validate_refname

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 26, 2006, 07:55 UTC
Message-ID
<200609260955.02869.jnareb@gmail.com>
In-Reply-To
<7v1wpzw9l9.fsf@assigned-by-dhcp.cox.net>
Dnia wtorek 26. września 2006 06:11, Junio C Hamano napisał:
> Jakub Narebski <jnareb@gmail.com> writes:
> 
> > @@ -387,16 +400,37 @@ sub href(%) {
> >  ## 
======================================================================
Show 27 quoted lines
> >  ## validation, quoting/unquoting and escaping
> >  
> > -sub validate_input {
> > -	my $input = shift;
> > +sub validate_pathname {
> > +	my $input = shift || return undef;
> >  
> > -	if ($input =~ m/^[0-9a-fA-F]{40}$/) {
> > -		return $input;
> > +	# no '.' or '..' as elements of path, i.e. no '.' nor '..'
> > +	# at the beginning, at the end, and between slashes.
> > +	if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
> > +		return undef;
> >  	}
> > -	if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
> > +	# no doubled slashes
> > +	if ($input =~ m!//!) {
> >  		return undef;
> >  	}
> 
> I do not think you need the second check for double-slash.  The
> pattern you borrowed from the original:
> 
> 	/(^|\/)(|\.|\.\.)($|\/)/)
> 
> cleverly matches an empty string with $2, so you already match
> double-slash with $1 = '/' $2 = '' $3 = '/', don't you?
Do I need to resend patch, then, to remove this unnecessary check?
Show 9 quoted lines
> > +	# it must be correct pathname
> > +	$input = validate_pathname($input)
> > +		or return undef;
> > +	# restrictions on ref name according to git-check-ref-format
> > +	if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
> >  		return undef;
> >  	}
> 
> Why would you need validate_pathname here?

refname _must_ be a valid pathname, no? It means for example that it cannot have double slashes, not NUL (the only thinkg not covered by git-check-ref-format restrictions). Well, we could add that to regexp instead...

-- 
Jakub Narebski
Poland
Previous: Junio C HamanoNext: Jakub Narebski
Message 6 of 10 in “gitweb: A few code cleanup patches”
  1. 0/5 gitweb: A few code cleanup patchesJakub Narebski, Sep 25, 2006
  2. 1/5 gitweb: Strip trailing slashes from $path in git_get_hash_by_pathJakub Narebski, Sep 25, 2006
  3. 2/5 gitweb: Use "return" instead of "return undef" for some subsJakub Narebski, Sep 25, 2006
  4. 3/5 gitweb: Split validate_input into validate_pathname and validate_refnameJakub Narebski, Sep 25, 2006
  5. Junio C HamanoSep 26, 2006
  6. Jakub NarebskiSep 26, 2006
  7. 4/5 gitweb: Add git_url subroutine, and use it to quote full URLsJakub Narebski, Sep 25, 2006
  8. 5/5 gitweb: Quote filename in HTTP Content-Disposition: headerJakub Narebski, Sep 25, 2006
  9. Junio C HamanoSep 26, 2006
  10. Jakub NarebskiSep 26, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.