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> 2001-12-28 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_mailto.in: Use the new OUTOFBAND indicator so gpg knows * gpgkeys_mailto.in: Use the new OUTOFBAND indicator so gpg knows
@ -35,7 +39,7 @@
gpgkeys_mailto (email keyserver helper) 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 This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without 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 /* 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. * This file is part of GnuPG.
* *
@ -44,7 +44,7 @@ FILE *input=NULL,*output=NULL,*console=NULL;
struct keylist struct keylist
{ {
char *keystr; char str[MAX_LINE];
struct keylist *next; struct keylist *next;
}; };
@ -146,6 +146,7 @@ int send_key(LDAP *ldap,char *keyid)
fail: fail:
free(key[0]); free(key[0]);
free(dn);
return ret; return ret;
} }
@ -220,7 +221,7 @@ int get_key(LDAP *ldap,char *getkey)
{ {
while(keyptr!=NULL) while(keyptr!=NULL)
{ {
if(strcasecmp(keyptr->keystr,vals[0])==0) if(strcasecmp(keyptr->str,vals[0])==0)
break; break;
keyptr=keyptr->next; keyptr=keyptr->next;
@ -238,13 +239,8 @@ int get_key(LDAP *ldap,char *getkey)
goto fail; goto fail;
} }
keyptr->keystr=strdup(vals[0]); strncpy(keyptr->str,vals[0],MAX_LINE);
if(keyptr->keystr==NULL) keyptr->str[MAX_LINE-1]='\0';
{
fprintf(console,"gpgkeys: out of memory when deduping "
"key list\n");
goto fail;
}
keyptr->next=dupelist; keyptr->next=dupelist;
dupelist=keyptr; dupelist=keyptr;
@ -360,7 +356,6 @@ int get_key(LDAP *ldap,char *getkey)
struct keylist *keyptr=dupelist; struct keylist *keyptr=dupelist;
dupelist=keyptr->next; dupelist=keyptr->next;
free(keyptr->keystr);
free(keyptr); free(keyptr);
} }
@ -705,55 +700,40 @@ int main(int argc,char *argv[])
while(fgets(line,MAX_LINE,input)!=NULL && line[0]!='\n'); while(fgets(line,MAX_LINE,input)!=NULL && line[0]!='\n');
else if(action==GET || action==SEARCH) else if(action==GET || action==SEARCH)
{ {
keylist=malloc(sizeof(struct keylist)); for(;;)
if(keylist==NULL)
{ {
fprintf(console,"gpgkeys: out of memory when building key list\n"); struct keylist *work;
goto fail;
}
keyptr=keylist; if(fgets(line,MAX_LINE,input)==NULL)
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;
break; 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 */ /* Trim the trailing \n */
len=strlen(keyptr->keystr); work->str[strlen(line)-1]='\0';
if(len>1)
keyptr->keystr[len-1]='\0';
keyptr->next=malloc(sizeof(struct keylist)); work->next=NULL;
if(keyptr->next==NULL)
{
fprintf(console,"gpgkeys: out of memory when "
"building key list\n");
goto fail;
}
keyptr=keyptr->next; /* Always attach at the end to keep the list in proper
keyptr->next=NULL; order for searching */
if(keylist==NULL)
keylist=work;
else
keyptr->next=work;
keyptr->keystr=malloc(MAX_LINE); keyptr=work;
if(keyptr->keystr==NULL)
{
fprintf(console,"gpgkeys: out of memory when "
"building key list\n");
goto fail;
} }
} }
} }
@ -850,16 +830,15 @@ int main(int argc,char *argv[])
case GET: case GET:
keyptr=keylist; keyptr=keylist;
while(keyptr->keystr!=NULL) while(keyptr!=NULL)
{ {
struct keylist *current=keyptr; struct keylist *current=keyptr;
get_key(ldap,current->keystr); get_key(ldap,current->str);
keyptr=current->next; keyptr=current->next;
/* Free it as we go */ /* Free it as we go */
free(current->keystr);
free(current); free(current);
} }
break; break;
@ -888,9 +867,9 @@ int main(int argc,char *argv[])
"enters words" */ "enters words" */
keyptr=keylist; keyptr=keylist;
while(keyptr->keystr!=NULL) while(keyptr!=NULL)
{ {
len+=strlen(keyptr->keystr)+1; len+=strlen(keyptr->str)+1;
keyptr=keyptr->next; keyptr=keyptr->next;
} }
@ -901,16 +880,15 @@ int main(int argc,char *argv[])
searchkey[0]='\0'; searchkey[0]='\0';
keyptr=keylist; keyptr=keylist;
while(keyptr->keystr!=NULL) while(keyptr!=NULL)
{ {
struct keylist *current=keyptr; struct keylist *current=keyptr;
strcat(searchkey,current->keystr); strcat(searchkey,current->str);
strcat(searchkey,"*"); strcat(searchkey,"*");
keyptr=current->next; keyptr=current->next;
/* Free it as we go */ /* Free it as we go */
free(current->keystr);
free(current); free(current);
} }