@@ -150,7 +150,6 @@ static char *path_ok(char *directory)
150150{
151151 static char rpath [PATH_MAX ];
152152 static char interp_path [PATH_MAX ];
153- int retried_path = 0 ;
154153 char * path ;
155154 char * dir ;
156155
@@ -219,22 +218,15 @@ static char *path_ok(char *directory)
219218 dir = rpath ;
220219 }
221220
222- do {
223- path = enter_repo (dir , strict_paths );
224- if (path )
225- break ;
226-
221+ path = enter_repo (dir , strict_paths );
222+ if (!path && base_path && base_path_relaxed ) {
227223 /*
228224 * if we fail and base_path_relaxed is enabled, try without
229225 * prefixing the base path
230226 */
231- if (base_path && base_path_relaxed && !retried_path ) {
232- dir = directory ;
233- retried_path = 1 ;
234- continue ;
235- }
236- break ;
237- } while (1 );
227+ dir = directory ;
228+ path = enter_repo (dir , strict_paths );
229+ }
238230
239231 if (!path ) {
240232 logerror ("'%s': unable to chdir or not a git archive" , dir );
@@ -405,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)
405397 die ("No such service %s" , name );
406398}
407399
400+ static char * xstrdup_tolower (const char * str )
401+ {
402+ char * p , * dup = xstrdup (str );
403+ for (p = dup ; * p ; p ++ )
404+ * p = tolower (* p );
405+ return dup ;
406+ }
407+
408408/*
409409 * Separate the "extra args" information as supplied by the client connection.
410410 */
@@ -413,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
413413 char * val ;
414414 int vallen ;
415415 char * end = extra_args + buflen ;
416- char * hp ;
417416
418417 while (extra_args < end && * extra_args ) {
419418 saw_extended_args = 1 ;
@@ -431,28 +430,19 @@ static void parse_extra_args(char *extra_args, int buflen)
431430 tcp_port = xstrdup (port );
432431 }
433432 free (hostname );
434- hostname = xstrdup (host );
433+ hostname = xstrdup_tolower (host );
435434 }
436435
437436 /* On to the next one */
438437 extra_args = val + vallen ;
439438 }
440439 }
441440
442- /*
443- * Replace literal host with lowercase-ized hostname.
444- */
445- hp = hostname ;
446- if (!hp )
447- return ;
448- for ( ; * hp ; hp ++ )
449- * hp = tolower (* hp );
450-
451441 /*
452442 * Locate canonical hostname and its IP address.
453443 */
444+ if (hostname ) {
454445#ifndef NO_IPV6
455- {
456446 struct addrinfo hints ;
457447 struct addrinfo * ai , * ai0 ;
458448 int gai ;
@@ -476,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
476466 }
477467 freeaddrinfo (ai0 );
478468 }
479- }
480469#else
481- {
482470 struct hostent * hent ;
483471 struct sockaddr_in sa ;
484472 char * * ap ;
@@ -499,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)
499487 canon_hostname = xstrdup (hent -> h_name );
500488 free (ip_address );
501489 ip_address = xstrdup (addrbuf );
502- }
503490#endif
491+ }
504492}
505493
506494
@@ -953,12 +941,8 @@ int main(int argc, char **argv)
953941 char * arg = argv [i ];
954942
955943 if (!prefixcmp (arg , "--listen=" )) {
956- char * p = arg + 9 ;
957- char * ph = listen_addr = xmalloc (strlen (arg + 9 ) + 1 );
958- while (* p )
959- * ph ++ = tolower (* p ++ );
960- * ph = 0 ;
961- continue ;
944+ listen_addr = xstrdup_tolower (arg + 9 );
945+ continue ;
962946 }
963947 if (!prefixcmp (arg , "--port=" )) {
964948 char * end ;
@@ -1118,7 +1102,9 @@ int main(int argc, char **argv)
11181102 struct sockaddr * peer = (struct sockaddr * )& ss ;
11191103 socklen_t slen = sizeof (ss );
11201104
1121- freopen ("/dev/null" , "w" , stderr );
1105+ if (!freopen ("/dev/null" , "w" , stderr ))
1106+ die ("failed to redirect stderr to /dev/null: %s" ,
1107+ strerror (errno ));
11221108
11231109 if (getpeername (0 , peer , & slen ))
11241110 peer = NULL ;
0 commit comments