1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Restructured the compat functions and changed its license.

New fucntion xstrconcat for future use.
This commit is contained in:
Werner Koch 2009-08-25 20:00:24 +00:00
parent f5f0171d55
commit 20fe42d10b
11 changed files with 193 additions and 24 deletions

View file

@ -1,3 +1,11 @@
2009-08-25 Werner Koch <wk@g10code.com>
* ksmalloc.c: New
(xtrymalloc, xfree): New.
* Makefile.am (gpgkeys_ldap_SOURCES, gpgkeys_curl_SOURCES):
(gpgkeys_hkp_SOURCES): Add ksmalloc.c.
* gpgkeys_hkp.c, gpgkeys_ldap.c: s/malloc/xtrymalloc/.
2009-07-06 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_hkp.c (main, srv_replace): Minor tweaks to use the

View file

@ -27,10 +27,10 @@ gpglibexec_PROGRAMS = @GPGKEYS_LDAP@ @GPGKEYS_HKP@ @GPGKEYS_FINGER@ @GPGKEYS_CUR
gpglibexec_SCRIPTS = @GPGKEYS_MAILTO@
noinst_SCRIPTS = gpgkeys_test
gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h
gpgkeys_hkp_SOURCES = gpgkeys_hkp.c ksutil.c ksutil.h
gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h ksmalloc.c
gpgkeys_hkp_SOURCES = gpgkeys_hkp.c ksutil.c ksutil.h ksmalloc.c
gpgkeys_finger_SOURCES = gpgkeys_finger.c ksutil.c ksutil.h
gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h
gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h ksmalloc.c
other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS)

View file

@ -288,7 +288,7 @@ curl_easy_escape(CURL *curl,char *str,int length)
else
len=strlen(str);
enc=malloc(len+1);
enc = xtrymalloc(len+1);
if(!enc)
return enc;

View file

@ -106,7 +106,7 @@ send_key(int *eof)
char *key=NULL,*encoded_key=NULL;
size_t keysize=1;
key=malloc(1);
key = xtrymalloc(1);
if(!key)
{
fprintf(console,"gpgkeys: unable to allocate memory for key\n");
@ -179,7 +179,7 @@ send_key(int *eof)
free(key);
key=malloc(8+strlen(encoded_key)+1);
key=xtrymalloc(8+strlen(encoded_key)+1);
if(!key)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -324,7 +324,7 @@ get_name(const char *getkey)
goto fail;
}
request=malloc(MAX_URL+60+strlen(searchkey_encoded));
request=xtrymalloc(MAX_URL+60+strlen(searchkey_encoded));
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -408,7 +408,7 @@ search_key(const char *searchkey)
goto fail;
}
request=malloc(MAX_URL+60+strlen(searchkey_encoded));
request=xtrymalloc(MAX_URL+60+strlen(searchkey_encoded));
if(!request)
{
fprintf(console,"gpgkeys: out of memory\n");
@ -519,7 +519,7 @@ srv_replace(const char *srvtag)
char *newname,*newport;
newname=strdup(srvlist->target);
newport=malloc(MAX_PORT);
newport=xtrymalloc(MAX_PORT);
if(newname && newport)
{
free(opt->host);
@ -803,7 +803,7 @@ main(int argc,char *argv[])
if(line[0]=='\n' || line[0]=='\0')
break;
work=malloc(sizeof(struct keylist));
work=xtrymalloc(sizeof(struct keylist));
if(work==NULL)
{
fprintf(console,"gpgkeys: out of memory while "
@ -909,7 +909,7 @@ main(int argc,char *argv[])
keyptr=keyptr->next;
}
searchkey=malloc(len+1);
searchkey=xtrymalloc(len+1);
if(searchkey==NULL)
{
ret=KEYSERVER_NO_MEMORY;

View file

@ -147,7 +147,7 @@ key_in_keylist(const char *key,struct keylist *list)
static int
add_key_to_keylist(const char *key,struct keylist **list)
{
struct keylist *keyptr=malloc(sizeof(struct keylist));
struct keylist *keyptr=xtrymalloc(sizeof(struct keylist));
if(keyptr==NULL)
{
@ -320,14 +320,14 @@ make_one_attr(LDAPMod ***modlist,char *attr,const char *value)
return 0;
*modlist=grow;
grow[nummods]=malloc(sizeof(LDAPMod));
grow[nummods]=xtrymalloc(sizeof(LDAPMod));
if(!grow[nummods])
return 0;
grow[nummods]->mod_op=LDAP_MOD_REPLACE;
grow[nummods]->mod_type=attr;
if(value)
{
grow[nummods]->mod_values=malloc(sizeof(char *)*2);
grow[nummods]->mod_values=xtrymalloc(sizeof(char *)*2);
if(!grow[nummods]->mod_values)
{
grow[nummods]=NULL;
@ -586,7 +586,7 @@ send_key(int *eof)
char keyid[17],state[6];
LDAPMod **modlist,**addlist,**ml;
modlist=malloc(sizeof(LDAPMod *));
modlist=xtrymalloc(sizeof(LDAPMod *));
if(!modlist)
{
fprintf(console,"gpgkeys: can't allocate memory for keyserver record\n");
@ -596,7 +596,7 @@ send_key(int *eof)
*modlist=NULL;
addlist=malloc(sizeof(LDAPMod *));
addlist=xtrymalloc(sizeof(LDAPMod *));
if(!addlist)
{
fprintf(console,"gpgkeys: can't allocate memory for keyserver record\n");
@ -647,7 +647,7 @@ send_key(int *eof)
goto fail;
}
dn=malloc(strlen("pgpCertID=")+16+1+strlen(basekeyspacedn)+1);
dn=xtrymalloc(strlen("pgpCertID=")+16+1+strlen(basekeyspacedn)+1);
if(dn==NULL)
{
fprintf(console,"gpgkeys: can't allocate memory for keyserver record\n");
@ -657,7 +657,7 @@ send_key(int *eof)
sprintf(dn,"pgpCertID=%s,%s",keyid,basekeyspacedn);
key=malloc(1);
key=xtrymalloc(1);
if(!key)
{
fprintf(console,"gpgkeys: unable to allocate memory for key\n");
@ -812,7 +812,7 @@ send_key_keyserver(int *eof)
attrs[0]=&mod;
attrs[1]=NULL;
dn=malloc(strlen("pgpCertid=virtual,")+strlen(basekeyspacedn)+1);
dn=xtrymalloc(strlen("pgpCertid=virtual,")+strlen(basekeyspacedn)+1);
if(dn==NULL)
{
fprintf(console,"gpgkeys: can't allocate memory for keyserver record\n");
@ -823,7 +823,7 @@ send_key_keyserver(int *eof)
strcpy(dn,"pgpCertid=virtual,");
strcat(dn,basekeyspacedn);
key[0]=malloc(1);
key[0]=xtrymalloc(1);
if(key[0]==NULL)
{
fprintf(console,"gpgkeys: unable to allocate memory for key\n");
@ -1308,7 +1308,7 @@ search_key(const char *searchkey)
"pgpkeysize","pgpkeytype",NULL};
enum ks_search_type search_type;
search=malloc(2+1+9+1+3+strlen(searchkey)+3+1+15+14+1+1+20);
search=xtrymalloc(2+1+9+1+3+strlen(searchkey)+3+1+15+14+1+1+20);
if(!search)
{
fprintf(console,"gpgkeys: out of memory when building search list\n");
@ -1671,7 +1671,7 @@ find_basekeyspacedn(void)
LDAPMessage *si_res;
char *object;
object=malloc(17+strlen(context[i])+1);
object=xtrymalloc(17+strlen(context[i])+1);
if(!object)
return -1;
@ -2042,7 +2042,7 @@ main(int argc,char *argv[])
if(line[0]=='\n' || line[0]=='\0')
break;
work=malloc(sizeof(struct keylist));
work=xtrymalloc(sizeof(struct keylist));
if(work==NULL)
{
fprintf(console,"gpgkeys: out of memory while "
@ -2326,7 +2326,7 @@ main(int argc,char *argv[])
keyptr=keyptr->next;
}
searchkey=malloc((len*3)+1);
searchkey=xtrymalloc((len*3)+1);
if(searchkey==NULL)
{
ret=KEYSERVER_NO_MEMORY;

32
keyserver/ksmalloc.c Normal file
View file

@ -0,0 +1,32 @@
/* ksmalloc.c - Walloc wrapper
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* The origin of this code is GnuPG.
*
* This file is free software; as a special exception the author gives
* unlimited permission to copy and/or distribute it, with or without
* modifications, as long as this notice is preserved.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdlib.h>
/* A wrapper around malloc because libcompat requires it. */
void *
xtrymalloc (size_t n)
{
return malloc (n);
}
/* A wrapper around free becuase we are used to it. */
void
xfree (void *p)
{
if (p)
free (p);
}

View file

@ -136,4 +136,9 @@ struct curl_writer_ctx
size_t curl_writer(const void *ptr,size_t size,size_t nmemb,void *cw_ctx);
void curl_writer_finalize(struct curl_writer_ctx *ctx);
/* -- From ksmalloc.c or ../include/memory.h -- */
void *xtrymalloc (size_t n);
void xfree (void *p);
#endif /* !_KSUTIL_H_ */