aboutsummaryrefslogtreecommitdiffstats
path: root/keyserver
diff options
context:
space:
mode:
Diffstat (limited to 'keyserver')
-rw-r--r--keyserver/ChangeLog8
-rw-r--r--keyserver/Makefile.am6
-rw-r--r--keyserver/curl-shim.c2
-rw-r--r--keyserver/gpgkeys_hkp.c14
-rw-r--r--keyserver/gpgkeys_ldap.c26
-rw-r--r--keyserver/ksmalloc.c32
-rw-r--r--keyserver/ksutil.h5
7 files changed, 69 insertions, 24 deletions
diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog
index 3b66fb92c..d2fd863f1 100644
--- a/keyserver/ChangeLog
+++ b/keyserver/ChangeLog
@@ -1,3 +1,11 @@
+2009-08-25 Werner Koch <[email protected]>
+
+ * 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 <[email protected]>
* gpgkeys_hkp.c (main, srv_replace): Minor tweaks to use the
diff --git a/keyserver/Makefile.am b/keyserver/Makefile.am
index feb102fcf..4c77a926c 100644
--- a/keyserver/Makefile.am
+++ b/keyserver/Makefile.am
@@ -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)
diff --git a/keyserver/curl-shim.c b/keyserver/curl-shim.c
index 0aab4ad67..2df782638 100644
--- a/keyserver/curl-shim.c
+++ b/keyserver/curl-shim.c
@@ -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;
diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c
index 54056e990..a15cbf656 100644
--- a/keyserver/gpgkeys_hkp.c
+++ b/keyserver/gpgkeys_hkp.c
@@ -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;
diff --git a/keyserver/gpgkeys_ldap.c b/keyserver/gpgkeys_ldap.c
index 4430ccbe1..453632502 100644
--- a/keyserver/gpgkeys_ldap.c
+++ b/keyserver/gpgkeys_ldap.c
@@ -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;
diff --git a/keyserver/ksmalloc.c b/keyserver/ksmalloc.c
new file mode 100644
index 000000000..ea7b0771e
--- /dev/null
+++ b/keyserver/ksmalloc.c
@@ -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);
+}
+
diff --git a/keyserver/ksutil.h b/keyserver/ksutil.h
index 21a146758..b2848ffd1 100644
--- a/keyserver/ksutil.h
+++ b/keyserver/ksutil.h
@@ -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_ */