aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2002-02-14 19:33:47 +0000
committerDavid Shaw <[email protected]>2002-02-14 19:33:47 +0000
commitc5f838a968637be4dad33e9036340979cd882e6e (patch)
tree4b476896bb7b1c81e803eec0d904536db7dfb566
parentdoc fixes (diff)
downloadgnupg-c5f838a968637be4dad33e9036340979cd882e6e.tar.gz
gnupg-c5f838a968637be4dad33e9036340979cd882e6e.zip
Be much more robust with mangled input files.
-rw-r--r--keyserver/ChangeLog6
-rw-r--r--keyserver/gpgkeys_ldap.c98
2 files changed, 43 insertions, 61 deletions
diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog
index f51d37494..45eed5820 100644
--- a/keyserver/ChangeLog
+++ b/keyserver/ChangeLog
@@ -1,3 +1,7 @@
+2002-02-14 David Shaw <[email protected]>
+
+ * gpgkeys_ldap.c: Be much more robust with mangled input files.
+
2001-12-28 David Shaw <[email protected]>
* gpgkeys_mailto.in: Use the new OUTOFBAND indicator so gpg knows
@@ -35,7 +39,7 @@
gpgkeys_mailto (email keyserver helper)
- Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
diff --git a/keyserver/gpgkeys_ldap.c b/keyserver/gpgkeys_ldap.c
index 3f979cb21..ae5d4342a 100644
--- a/keyserver/gpgkeys_ldap.c
+++ b/keyserver/gpgkeys_ldap.c
@@ -1,5 +1,5 @@
/* gpgkeys_ldap.c - talk to a LDAP keyserver
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -44,7 +44,7 @@ FILE *input=NULL,*output=NULL,*console=NULL;
struct keylist
{
- char *keystr;
+ char str[MAX_LINE];
struct keylist *next;
};
@@ -146,6 +146,7 @@ int send_key(LDAP *ldap,char *keyid)
fail:
free(key[0]);
+ free(dn);
return ret;
}
@@ -220,7 +221,7 @@ int get_key(LDAP *ldap,char *getkey)
{
while(keyptr!=NULL)
{
- if(strcasecmp(keyptr->keystr,vals[0])==0)
+ if(strcasecmp(keyptr->str,vals[0])==0)
break;
keyptr=keyptr->next;
@@ -238,13 +239,8 @@ int get_key(LDAP *ldap,char *getkey)
goto fail;
}
- keyptr->keystr=strdup(vals[0]);
- if(keyptr->keystr==NULL)
- {
- fprintf(console,"gpgkeys: out of memory when deduping "
- "key list\n");
- goto fail;
- }
+ strncpy(keyptr->str,vals[0],MAX_LINE);
+ keyptr->str[MAX_LINE-1]='\0';
keyptr->next=dupelist;
dupelist=keyptr;
@@ -360,7 +356,6 @@ int get_key(LDAP *ldap,char *getkey)
struct keylist *keyptr=dupelist;
dupelist=keyptr->next;
- free(keyptr->keystr);
free(keyptr);
}
@@ -705,55 +700,40 @@ int main(int argc,char *argv[])
while(fgets(line,MAX_LINE,input)!=NULL && line[0]!='\n');
else if(action==GET || action==SEARCH)
{
- keylist=malloc(sizeof(struct keylist));
- if(keylist==NULL)
+ for(;;)
{
- fprintf(console,"gpgkeys: out of memory when building key list\n");
- goto fail;
- }
+ struct keylist *work;
- keyptr=keylist;
-
- keyptr->keystr=malloc(MAX_LINE);
- if(keyptr->keystr==NULL)
- {
- fprintf(console,"gpgkeys: out of memory when building key list\n");
- goto fail;
- }
+ if(fgets(line,MAX_LINE,input)==NULL)
+ break;
+ else
+ {
+ if(line[0]=='\n')
+ break;
- while(fgets(keyptr->keystr,MAX_LINE,input)!=NULL)
- {
- int len;
+ work=malloc(sizeof(struct keylist));
+ if(work==NULL)
+ {
+ fprintf(console,"gpgkeys: out of memory while "
+ "building key list\n");
+ goto fail;
+ }
- if(keyptr->keystr[0]=='\n')
- {
- free(keyptr->keystr);
- keyptr->keystr=NULL;
- break;
- }
+ strcpy(work->str,line);
- /* Trim the trailing \n */
- len=strlen(keyptr->keystr);
- if(len>1)
- keyptr->keystr[len-1]='\0';
+ /* Trim the trailing \n */
+ work->str[strlen(line)-1]='\0';
- keyptr->next=malloc(sizeof(struct keylist));
- if(keyptr->next==NULL)
- {
- fprintf(console,"gpgkeys: out of memory when "
- "building key list\n");
- goto fail;
- }
+ work->next=NULL;
- keyptr=keyptr->next;
- keyptr->next=NULL;
+ /* Always attach at the end to keep the list in proper
+ order for searching */
+ if(keylist==NULL)
+ keylist=work;
+ else
+ keyptr->next=work;
- keyptr->keystr=malloc(MAX_LINE);
- if(keyptr->keystr==NULL)
- {
- fprintf(console,"gpgkeys: out of memory when "
- "building key list\n");
- goto fail;
+ keyptr=work;
}
}
}
@@ -850,16 +830,15 @@ int main(int argc,char *argv[])
case GET:
keyptr=keylist;
- while(keyptr->keystr!=NULL)
+ while(keyptr!=NULL)
{
struct keylist *current=keyptr;
- get_key(ldap,current->keystr);
+ get_key(ldap,current->str);
keyptr=current->next;
/* Free it as we go */
- free(current->keystr);
free(current);
}
break;
@@ -888,9 +867,9 @@ int main(int argc,char *argv[])
"enters words" */
keyptr=keylist;
- while(keyptr->keystr!=NULL)
+ while(keyptr!=NULL)
{
- len+=strlen(keyptr->keystr)+1;
+ len+=strlen(keyptr->str)+1;
keyptr=keyptr->next;
}
@@ -901,16 +880,15 @@ int main(int argc,char *argv[])
searchkey[0]='\0';
keyptr=keylist;
- while(keyptr->keystr!=NULL)
+ while(keyptr!=NULL)
{
struct keylist *current=keyptr;
- strcat(searchkey,current->keystr);
+ strcat(searchkey,current->str);
strcat(searchkey,"*");
keyptr=current->next;
/* Free it as we go */
- free(current->keystr);
free(current);
}