[svn] GnuPG - r5127 - in branches/STABLE-BRANCH-1-4: include keyserver util

svn author wk cvs at cvs.gnupg.org
Tue Aug 25 22:00:24 CEST 2009


Author: wk
Date: 2009-08-25 22:00:24 +0200 (Tue, 25 Aug 2009)
New Revision: 5127

Added:
   branches/STABLE-BRANCH-1-4/keyserver/ksmalloc.c
Modified:
   branches/STABLE-BRANCH-1-4/include/ChangeLog
   branches/STABLE-BRANCH-1-4/include/compat.h
   branches/STABLE-BRANCH-1-4/keyserver/ChangeLog
   branches/STABLE-BRANCH-1-4/keyserver/Makefile.am
   branches/STABLE-BRANCH-1-4/keyserver/curl-shim.c
   branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_hkp.c
   branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_ldap.c
   branches/STABLE-BRANCH-1-4/keyserver/ksutil.h
   branches/STABLE-BRANCH-1-4/util/ChangeLog
   branches/STABLE-BRANCH-1-4/util/compat.c
Log:
Restructured the compat functions and changed its license.
New fucntion xstrconcat for future use.


Modified: branches/STABLE-BRANCH-1-4/include/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-1-4/include/ChangeLog	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/include/ChangeLog	2009-08-25 20:00:24 UTC (rev 5127)
@@ -1,3 +1,7 @@
+2009-08-25  Werner Koch  <wk at g10code.com>
+
+	* compat.h: Add xstrconcat.
+
 2009-08-11  David Shaw  <dshaw at jabberwocky.com>
 
 	* util.h: Add string_to_utf8() from GPA.

Modified: branches/STABLE-BRANCH-1-4/keyserver/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/ChangeLog	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/ChangeLog	2009-08-25 20:00:24 UTC (rev 5127)
@@ -1,3 +1,11 @@
+2009-08-25  Werner Koch  <wk at 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 at jabberwocky.com>
 
 	* gpgkeys_hkp.c (main, srv_replace): Minor tweaks to use the

Modified: branches/STABLE-BRANCH-1-4/util/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-1-4/util/ChangeLog	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/util/ChangeLog	2009-08-25 20:00:24 UTC (rev 5127)
@@ -1,3 +1,9 @@
+2009-08-25  Werner Koch  <wk at g10code.com>
+
+	* compat.c: Change license to all-permissive.  The GPL and the
+	exception does no make sense here.
+	(do_strconcat, xstrconcat): New.
+
 2009-08-18  Werner Koch  <wk at g10code.com>
 
 	* iobuf.c (fd_cache_close): Change debug printf format assuming

Modified: branches/STABLE-BRANCH-1-4/include/compat.h
===================================================================
--- branches/STABLE-BRANCH-1-4/include/compat.h	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/include/compat.h	2009-08-25 20:00:24 UTC (rev 5127)
@@ -15,4 +15,11 @@
 char *strsep (char **stringp, const char *delim);
 #endif
 
+#if __GNUC__ >= 4 
+char *xstrconcat (const char *s1, ...) __attribute__ ((sentinel(0)));
+#else
+char *xstrconcat (const char *s1, ...);
+#endif
+
+
 #endif /* !_COMPAT_H_ */

Modified: branches/STABLE-BRANCH-1-4/keyserver/Makefile.am
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/Makefile.am	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/Makefile.am	2009-08-25 20:00:24 UTC (rev 5127)
@@ -27,10 +27,10 @@
 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)
 

Modified: branches/STABLE-BRANCH-1-4/keyserver/curl-shim.c
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/curl-shim.c	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/curl-shim.c	2009-08-25 20:00:24 UTC (rev 5127)
@@ -288,7 +288,7 @@
   else
     len=strlen(str);
 
-  enc=malloc(len+1);
+  enc = xtrymalloc(len+1);
   if(!enc)
     return enc;
 

Modified: branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_hkp.c
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_hkp.c	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_hkp.c	2009-08-25 20:00:24 UTC (rev 5127)
@@ -106,7 +106,7 @@
   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 @@
 
   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 @@
       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 @@
       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 @@
       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 @@
 	      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 @@
 	  keyptr=keyptr->next;
 	}
 
-      searchkey=malloc(len+1);
+      searchkey=xtrymalloc(len+1);
       if(searchkey==NULL)
 	{
 	  ret=KEYSERVER_NO_MEMORY;

Modified: branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_ldap.c
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_ldap.c	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/gpgkeys_ldap.c	2009-08-25 20:00:24 UTC (rev 5127)
@@ -147,7 +147,7 @@
 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 @@
 	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 @@
   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 @@
 
   *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 @@
       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 @@
 
   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 @@
   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 @@
   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 @@
 		 "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 @@
 	      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 @@
 	      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 @@
 	  keyptr=keyptr->next;
 	}
 
-      searchkey=malloc((len*3)+1);
+      searchkey=xtrymalloc((len*3)+1);
       if(searchkey==NULL)
 	{
 	  ret=KEYSERVER_NO_MEMORY;

Added: branches/STABLE-BRANCH-1-4/keyserver/ksmalloc.c
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/ksmalloc.c	                        (rev 0)
+++ branches/STABLE-BRANCH-1-4/keyserver/ksmalloc.c	2009-08-25 20:00:24 UTC (rev 5127)
@@ -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);
+}
+

Modified: branches/STABLE-BRANCH-1-4/keyserver/ksutil.h
===================================================================
--- branches/STABLE-BRANCH-1-4/keyserver/ksutil.h	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/keyserver/ksutil.h	2009-08-25 20:00:24 UTC (rev 5127)
@@ -136,4 +136,9 @@
 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_ */

Modified: branches/STABLE-BRANCH-1-4/util/compat.c
===================================================================
--- branches/STABLE-BRANCH-1-4/util/compat.c	2009-08-24 22:21:39 UTC (rev 5126)
+++ branches/STABLE-BRANCH-1-4/util/compat.c	2009-08-25 20:00:24 UTC (rev 5127)
@@ -1,5 +1,42 @@
+/* compat.c - Simple compatibility functions
+ * Copyright (C) 2006, 2007, 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.
+ *
+ * History:
+ * 2006-09-28 dshaw  Created.  Added function hextobyte from GnuPG.
+ * 2007-04-16 dshaw  Added ascii_toupper, ascii_tolower, ascii_strcasecmp,
+ *                   ascii_strncasecmp from GnuPG.
+ * 2009-08-25 wk     License changed by GnuPG maintainer from GPL with 
+ *                   OpenSSL exception to this all permissive license.
+ * 2009-08-25 wk     Wrote new function xstrconcat.
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
 #include <sys/types.h>
 
+/* We require an external malloc function named xtrymalloc.  */
+void *xtrymalloc (size_t n);
+
+
+#ifndef DIM
+#define DIM(v) (sizeof(v)/sizeof((v)[0]))
+#endif
+
+
+
 int
 hextobyte (const char *s)
 {
@@ -92,3 +129,73 @@
   
   return c1 - c2;
 }
+
+
+static char *
+do_strconcat (const char *s1, va_list arg_ptr)
+{
+  const char *argv[48];
+  size_t argc;
+  size_t needed;
+  char *buffer, *p;
+  const char *r;
+
+  argc = 0;
+  argv[argc++] = s1;
+  needed = strlen (s1);
+  while (((argv[argc] = va_arg (arg_ptr, const char *))))
+    {
+      needed += strlen (argv[argc]);
+      if (argc >= DIM (argv)-1)
+        {
+          errno = EINVAL;
+          return NULL;
+        }
+      argc++;
+    }
+  needed++;
+  buffer = xtrymalloc (needed);
+  if (buffer)
+    {
+      for (p = buffer, argc=0; argv[argc]; argc++)
+        {
+          for (r = argv[argc]; *r; )
+            *p++ = *r++;
+          *p = 0;
+        }
+    }
+  return buffer;
+}
+
+
+/* Concatenate the string S1 with all the following strings up to a
+   NULL.  Returns a malloced buffer.  */
+char *
+xstrconcat (const char *s1, ...)
+{
+  va_list arg_ptr;
+  char *result;
+
+  if (!s1)
+    {
+      result = xtrymalloc (1);
+      if (result)
+        *result = 0;
+    }
+  else
+    {
+      va_start (arg_ptr, s1);
+      result = do_strconcat (s1, arg_ptr);
+      va_end (arg_ptr);
+    }
+  if (!result)
+    {
+      if (errno == EINVAL)
+        fputs ("\nfatal: too many args for xstrconcat\n", stderr);
+      else
+        fputs ("\nfatal: out of memory\n", stderr);
+      exit (2);
+    }
+  return result;
+}
+




More information about the Gnupg-commits mailing list