@@ -89,6 +89,11 @@ static int proto_is_http(const char *s)
89
89
90
90
static void credential_apply_config (struct credential * c )
91
91
{
92
+ if (!c -> host )
93
+ die (_ ("refusing to work with credential missing host field" ));
94
+ if (!c -> protocol )
95
+ die (_ ("refusing to work with credential missing protocol field" ));
96
+
92
97
if (c -> configured )
93
98
return ;
94
99
git_config (credential_config_callback , c );
@@ -191,8 +196,11 @@ int credential_read(struct credential *c, FILE *fp)
191
196
return 0 ;
192
197
}
193
198
194
- static void credential_write_item (FILE * fp , const char * key , const char * value )
199
+ static void credential_write_item (FILE * fp , const char * key , const char * value ,
200
+ int required )
195
201
{
202
+ if (!value && required )
203
+ BUG ("credential value for %s is missing" , key );
196
204
if (!value )
197
205
return ;
198
206
if (strchr (value , '\n' ))
@@ -202,11 +210,11 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
202
210
203
211
void credential_write (const struct credential * c , FILE * fp )
204
212
{
205
- credential_write_item (fp , "protocol" , c -> protocol );
206
- credential_write_item (fp , "host" , c -> host );
207
- credential_write_item (fp , "path" , c -> path );
208
- credential_write_item (fp , "username" , c -> username );
209
- credential_write_item (fp , "password" , c -> password );
213
+ credential_write_item (fp , "protocol" , c -> protocol , 1 );
214
+ credential_write_item (fp , "host" , c -> host , 1 );
215
+ credential_write_item (fp , "path" , c -> path , 0 );
216
+ credential_write_item (fp , "username" , c -> username , 0 );
217
+ credential_write_item (fp , "password" , c -> password , 0 );
210
218
}
211
219
212
220
static int run_credential_helper (struct credential * c ,
@@ -352,8 +360,11 @@ int credential_from_url_gently(struct credential *c, const char *url,
352
360
* (3) proto://<user>:<pass>@<host>/...
353
361
*/
354
362
proto_end = strstr (url , "://" );
355
- if (!proto_end )
356
- return 0 ;
363
+ if (!proto_end || proto_end == url ) {
364
+ if (!quiet )
365
+ warning (_ ("url has no scheme: %s" ), url );
366
+ return -1 ;
367
+ }
357
368
cp = proto_end + 3 ;
358
369
at = strchr (cp , '@' );
359
370
colon = strchr (cp , ':' );
@@ -374,10 +385,8 @@ int credential_from_url_gently(struct credential *c, const char *url,
374
385
host = at + 1 ;
375
386
}
376
387
377
- if (proto_end - url > 0 )
378
- c -> protocol = xmemdupz (url , proto_end - url );
379
- if (slash - host > 0 )
380
- c -> host = url_decode_mem (host , slash - host );
388
+ c -> protocol = xmemdupz (url , proto_end - url );
389
+ c -> host = url_decode_mem (host , slash - host );
381
390
/* Trim leading and trailing slashes from path */
382
391
while (* slash == '/' )
383
392
slash ++ ;
@@ -401,8 +410,6 @@ int credential_from_url_gently(struct credential *c, const char *url,
401
410
402
411
void credential_from_url (struct credential * c , const char * url )
403
412
{
404
- if (credential_from_url_gently (c , url , 0 ) < 0 ) {
405
- warning (_ ("skipping credential lookup for url: %s" ), url );
406
- credential_clear (c );
407
- }
413
+ if (credential_from_url_gently (c , url , 0 ) < 0 )
414
+ die (_ ("credential url cannot be parsed: %s" ), url );
408
415
}
0 commit comments