@@ -150,7 +150,6 @@ static char *path_ok(char *directory)
150
150
{
151
151
static char rpath [PATH_MAX ];
152
152
static char interp_path [PATH_MAX ];
153
- int retried_path = 0 ;
154
153
char * path ;
155
154
char * dir ;
156
155
@@ -219,22 +218,15 @@ static char *path_ok(char *directory)
219
218
dir = rpath ;
220
219
}
221
220
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 ) {
227
223
/*
228
224
* if we fail and base_path_relaxed is enabled, try without
229
225
* prefixing the base path
230
226
*/
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
+ }
238
230
239
231
if (!path ) {
240
232
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)
405
397
die ("No such service %s" , name );
406
398
}
407
399
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
+
408
408
/*
409
409
* Separate the "extra args" information as supplied by the client connection.
410
410
*/
@@ -413,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
413
413
char * val ;
414
414
int vallen ;
415
415
char * end = extra_args + buflen ;
416
- char * hp ;
417
416
418
417
while (extra_args < end && * extra_args ) {
419
418
saw_extended_args = 1 ;
@@ -431,28 +430,19 @@ static void parse_extra_args(char *extra_args, int buflen)
431
430
tcp_port = xstrdup (port );
432
431
}
433
432
free (hostname );
434
- hostname = xstrdup (host );
433
+ hostname = xstrdup_tolower (host );
435
434
}
436
435
437
436
/* On to the next one */
438
437
extra_args = val + vallen ;
439
438
}
440
439
}
441
440
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
-
451
441
/*
452
442
* Locate canonical hostname and its IP address.
453
443
*/
444
+ if (hostname ) {
454
445
#ifndef NO_IPV6
455
- {
456
446
struct addrinfo hints ;
457
447
struct addrinfo * ai , * ai0 ;
458
448
int gai ;
@@ -476,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
476
466
}
477
467
freeaddrinfo (ai0 );
478
468
}
479
- }
480
469
#else
481
- {
482
470
struct hostent * hent ;
483
471
struct sockaddr_in sa ;
484
472
char * * ap ;
@@ -499,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)
499
487
canon_hostname = xstrdup (hent -> h_name );
500
488
free (ip_address );
501
489
ip_address = xstrdup (addrbuf );
502
- }
503
490
#endif
491
+ }
504
492
}
505
493
506
494
@@ -953,12 +941,8 @@ int main(int argc, char **argv)
953
941
char * arg = argv [i ];
954
942
955
943
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 ;
962
946
}
963
947
if (!prefixcmp (arg , "--port=" )) {
964
948
char * end ;
@@ -1118,7 +1102,9 @@ int main(int argc, char **argv)
1118
1102
struct sockaddr * peer = (struct sockaddr * )& ss ;
1119
1103
socklen_t slen = sizeof (ss );
1120
1104
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 ));
1122
1108
1123
1109
if (getpeername (0 , peer , & slen ))
1124
1110
peer = NULL ;
0 commit comments