1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-23 10:29:58 +01:00

Be much more robust with mangled input files.

This commit is contained in:
David Shaw 2002-02-14 19:33:47 +00:00
parent 3034b6752e
commit c5f838a968
2 changed files with 44 additions and 62 deletions

View File

@ -1,3 +1,7 @@
2002-02-14 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_ldap.c: Be much more robust with mangled input files.
2001-12-28 David Shaw <dshaw@jabberwocky.com>
* 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

View File

@ -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;
}
while(fgets(keyptr->keystr,MAX_LINE,input)!=NULL)
{
int len;
if(keyptr->keystr[0]=='\n')
{
free(keyptr->keystr);
keyptr->keystr=NULL;
if(fgets(line,MAX_LINE,input)==NULL)
break;
else
{
if(line[0]=='\n')
break;
work=malloc(sizeof(struct keylist));
if(work==NULL)
{
fprintf(console,"gpgkeys: out of memory while "
"building key list\n");
goto fail;
}
strcpy(work->str,line);
/* Trim the trailing \n */
len=strlen(keyptr->keystr);
if(len>1)
keyptr->keystr[len-1]='\0';
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);
}