From 4e9797031ff18db2134aca728f72785862559bdd Mon Sep 17 00:00:00 2001 From: David Shaw Date: Tue, 21 Jun 2005 04:24:10 +0000 Subject: [PATCH] * gpgkeys_hkp.c (append_path, send_key, get_key, search_key, main), gpgkeys_oldhkp.c (main): Properly handle double slashes in paths. --- keyserver/ChangeLog | 6 ++++++ keyserver/gpgkeys_hkp.c | 29 +++++++++++++++++++---------- keyserver/gpgkeys_oldhkp.c | 8 +++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog index d73b9e33f..f751fed18 100644 --- a/keyserver/ChangeLog +++ b/keyserver/ChangeLog @@ -1,3 +1,9 @@ +2005-06-20 David Shaw + + * gpgkeys_hkp.c (append_path, send_key, get_key, search_key, + main), gpgkeys_oldhkp.c (main): Properly handle double slashes in + paths. + 2005-06-05 David Shaw * ksutil.c (init_ks_options, parse_ks_options): Provide a default diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c index b6da64b65..66f5a2cb0 100644 --- a/keyserver/gpgkeys_hkp.c +++ b/keyserver/gpgkeys_hkp.c @@ -69,6 +69,18 @@ curl_mrindex_writer(const void *ptr,size_t size,size_t nmemb,void *stream) return 0; } +/* Append but avoid creating a double slash // in the path. */ +static char * +append_path(char *dest,const char *src) +{ + size_t n=strlen(dest); + + if(src[0]=='/' && n>0 && dest[n-1]=='/') + dest[n-1]='\0'; + + return strcat(dest,src); +} + int send_key(int *eof) { @@ -162,11 +174,10 @@ send_key(int *eof) strcat(request,opt->port); else strcat(request,"11371"); - if(opt->path) - strcat(request,opt->path); + strcat(request,opt->path); /* request is MAX_URL+15 bytes long - MAX_URL covers the whole URL, including any supplied path. The 15 covers /pks/add. */ - strcat(request,"/pks/add"); + append_path(request,"/pks/add"); if(opt->verbose>2) fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request); @@ -229,12 +240,11 @@ get_key(char *getkey) strcat(request,opt->port); else strcat(request,"11371"); - if(opt->path) - strcat(request,opt->path); + strcat(request,opt->path); /* request is MAX_URL+55 bytes long - MAX_URL covers the whole URL, including any supplied path. The 60 overcovers this /pks/... etc string plus the 8 bytes of key id */ - strcat(request,"/pks/lookup?op=get&options=mr&search=0x"); + append_path(request,"/pks/lookup?op=get&options=mr&search=0x"); /* fingerprint or long key id. Take the last 8 characters and treat it like a short key id */ @@ -301,9 +311,8 @@ search_key(char *searchkey) strcat(request,opt->port); else strcat(request,"11371"); - if(opt->path) - strcat(request,opt->path); - strcat(request,"/pks/lookup?op=index&options=mr&search="); + strcat(request,opt->path); + append_path(request,"/pks/lookup?op=index&options=mr&search="); strcat(request,searchkey_encoded); if(opt->verbose>2) @@ -599,7 +608,7 @@ main(int argc,char *argv[]) fprintf(console,"Host:\t\t%s\n",opt->host); if(opt->port) fprintf(console,"Port:\t\t%s\n",opt->port); - if(opt->path) + if(strcmp(opt->path,"/")!=0) fprintf(console,"Path:\t\t%s\n",opt->path); fprintf(console,"Command:\t%s\n",ks_action_to_string(opt->action)); } diff --git a/keyserver/gpgkeys_oldhkp.c b/keyserver/gpgkeys_oldhkp.c index e2345f708..30c0773af 100644 --- a/keyserver/gpgkeys_oldhkp.c +++ b/keyserver/gpgkeys_oldhkp.c @@ -761,6 +761,7 @@ main(int argc,char *argv[]) int failed=0; struct keylist *keylist=NULL,*keyptr=NULL; unsigned int timeout=DEFAULT_KEYSERVER_TIMEOUT; + size_t n; console=stderr; @@ -956,6 +957,11 @@ main(int argc,char *argv[]) } } + /* Avoid the double slash // in a path */ + n=strlen(path); + if(n>0 && path[n-1]=='/') + path[n-1]='\0'; + if(timeout && register_timeout()==-1) { fprintf(console,"gpgkeys: unable to register timeout handler\n"); @@ -1028,7 +1034,7 @@ main(int argc,char *argv[]) fprintf(console,"Host:\t\t%s\n",host); if(port[0]) fprintf(console,"Port:\t\t%s\n",port); - if(path[0]) + if(strcmp(path,"/")!=0) fprintf(console,"Path:\t\t%s\n",path); fprintf(console,"Command:\t%s\n",action==GET?"GET": action==SEND?"SEND":"SEARCH");