@@ -195,6 +195,8 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
195
195
{
196
196
if (!value )
197
197
return ;
198
+ if (strchr (value , '\n' ))
199
+ die ("credential value for %s contains newline" , key );
198
200
fprintf (fp , "%s=%s\n" , key , value );
199
201
}
200
202
@@ -322,7 +324,22 @@ void credential_reject(struct credential *c)
322
324
c -> approved = 0 ;
323
325
}
324
326
325
- void credential_from_url (struct credential * c , const char * url )
327
+ static int check_url_component (const char * url , int quiet ,
328
+ const char * name , const char * value )
329
+ {
330
+ if (!value )
331
+ return 0 ;
332
+ if (!strchr (value , '\n' ))
333
+ return 0 ;
334
+
335
+ if (!quiet )
336
+ warning (_ ("url contains a newline in its %s component: %s" ),
337
+ name , url );
338
+ return -1 ;
339
+ }
340
+
341
+ int credential_from_url_gently (struct credential * c , const char * url ,
342
+ int quiet )
326
343
{
327
344
const char * at , * colon , * cp , * slash , * host , * proto_end ;
328
345
@@ -336,7 +353,7 @@ void credential_from_url(struct credential *c, const char *url)
336
353
*/
337
354
proto_end = strstr (url , "://" );
338
355
if (!proto_end )
339
- return ;
356
+ return 0 ;
340
357
cp = proto_end + 3 ;
341
358
at = strchr (cp , '@' );
342
359
colon = strchr (cp , ':' );
@@ -371,4 +388,21 @@ void credential_from_url(struct credential *c, const char *url)
371
388
while (p > c -> path && * p == '/' )
372
389
* p -- = '\0' ;
373
390
}
391
+
392
+ if (check_url_component (url , quiet , "username" , c -> username ) < 0 ||
393
+ check_url_component (url , quiet , "password" , c -> password ) < 0 ||
394
+ check_url_component (url , quiet , "protocol" , c -> protocol ) < 0 ||
395
+ check_url_component (url , quiet , "host" , c -> host ) < 0 ||
396
+ check_url_component (url , quiet , "path" , c -> path ) < 0 )
397
+ return -1 ;
398
+
399
+ return 0 ;
400
+ }
401
+
402
+ void credential_from_url (struct credential * c , const char * url )
403
+ {
404
+ if (credential_from_url_gently (c , url , 0 ) < 0 ) {
405
+ warning (_ ("skipping credential lookup for url: %s" ), url );
406
+ credential_clear (c );
407
+ }
374
408
}
0 commit comments