[svn] GnuPG - r4102 - trunk/keyserver

svn author dshaw cvs at cvs.gnupg.org
Tue Apr 11 05:25:25 CEST 2006


Author: dshaw
Date: 2006-04-11 05:25:25 +0200 (Tue, 11 Apr 2006)
New Revision: 4102

Modified:
   trunk/keyserver/ChangeLog
   trunk/keyserver/gpgkeys_ldap.c
Log:
* gpgkeys_ldap.c (ldap_quote, get_name, search_key): LDAP-quote
directly into place rather than mallocing temporary buffers.


Modified: trunk/keyserver/ChangeLog
===================================================================
--- trunk/keyserver/ChangeLog	2006-04-11 03:13:46 UTC (rev 4101)
+++ trunk/keyserver/ChangeLog	2006-04-11 03:25:25 UTC (rev 4102)
@@ -1,5 +1,8 @@
 2006-04-10  David Shaw  <dshaw at jabberwocky.com>
 
+	* gpgkeys_ldap.c (ldap_quote, get_name, search_key): LDAP-quote
+	directly into place rather than mallocing temporary buffers.
+
 	* gpgkeys_ldap.c (get_name): Build strings with strcat rather than
 	using sprintf which is harder to read and modify.
 

Modified: trunk/keyserver/gpgkeys_ldap.c
===================================================================
--- trunk/keyserver/gpgkeys_ldap.c	2006-04-11 03:13:46 UTC (rev 4101)
+++ trunk/keyserver/gpgkeys_ldap.c	2006-04-11 03:25:25 UTC (rev 4102)
@@ -1121,36 +1121,25 @@
 
 #define LDAP_ESCAPE_CHARS "*()\\"
 
-static int
+/* Append string to buffer in a LDAP-quoted way */
+static void
 ldap_quote(char *buffer,const char *string)
 {
-  int count=0;
+  /* Find the end of buffer */
+  buffer+=strlen(buffer);
 
   for(;*string;string++)
     {
       if(strchr(LDAP_ESCAPE_CHARS,*string))
 	{
-	  if(buffer)
-	    {
-	      sprintf(buffer,"\\%02X",*string);
-	      buffer+=3;
-	    }
-
-	  count+=3;
+	  sprintf(buffer,"\\%02X",*string);
+	  buffer+=3;
 	}
       else
-	{
-	  if(buffer)
-	    *buffer++=*string;
-
-	  count++;
-	}
+	*buffer++=*string;
     }
 
-  if(buffer)
-    *buffer='\0';
-
-  return count;
+  *buffer='\0';
 }
 
 /* Note that key-not-found is not a fatal error */
@@ -1159,7 +1148,6 @@
 {
   LDAPMessage *res,*each;
   int ret=KEYSERVER_INTERNAL_ERROR,err,count;
-  char *expanded_search;
   /* The maximum size of the search, including the optional stuff and
      the trailing \0 */
   char search[2+12+(MAX_LINE*3)+2+15+14+1+1+20];
@@ -1172,16 +1160,6 @@
   attrs[0]=pgpkeystr; /* Some compilers don't like using variables as
                          array initializers. */
 
-  expanded_search=malloc(ldap_quote(NULL,getkey)+1);
-  if(!expanded_search)
-    {
-      fprintf(output,"NAME %s FAILED %d\n",getkey,KEYSERVER_NO_MEMORY);
-      fprintf(console,"Out of memory when quoting LDAP search string\n");
-      return KEYSERVER_NO_MEMORY;
-    }
-
-  ldap_quote(expanded_search,getkey);
-
   /* Build the search string */
 
   search[0]='\0';
@@ -1190,7 +1168,7 @@
     strcat(search,"(&");
 
   strcat(search,"(pgpUserID=*");
-  strcat(search,expanded_search);
+  ldap_quote(search,getkey);
   strcat(search,"*)");
 
   if(!opt->flags.include_disabled)
@@ -1202,8 +1180,6 @@
   if(!opt->flags.include_disabled || !opt->flags.include_revoked)
     strcat(search,")");
 
-  free(expanded_search);
-
   if(opt->verbose>2)
     fprintf(console,"gpgkeys: LDAP fetch for: %s\n",search);
 
@@ -1299,7 +1275,6 @@
   LDAPMessage *res,*each;
   int err,count=0;
   struct keylist *dupelist=NULL;
-  char *expanded_search;
   /* The maximum size of the search, including the optional stuff and
      the trailing \0 */
   char search[2+1+9+1+3+(MAX_LINE*3)+3+1+15+14+1+1+20];
@@ -1316,16 +1291,6 @@
     fprintf(console,"search type is %d, and key is \"%s\"\n",
 	    search_type,searchkey);
 
-  expanded_search=malloc(ldap_quote(NULL,searchkey)+1);
-  if(!expanded_search)
-    {
-      fprintf(output,"SEARCH %s FAILED %d\n",searchkey,KEYSERVER_NO_MEMORY);
-      fprintf(console,"Out of memory when quoting LDAP search string\n");
-      return KEYSERVER_NO_MEMORY;
-    }
-
-  ldap_quote(expanded_search,searchkey);
-
   /* Build the search string */
 
   search[0]='\0';
@@ -1372,7 +1337,7 @@
       break;
     }
 
-  strcat(search,expanded_search);
+  ldap_quote(search,searchkey);
 
   switch(search_type)
     {
@@ -1405,8 +1370,6 @@
   if(!opt->flags.include_disabled || !opt->flags.include_revoked)
     strcat(search,")");
 
-  free(expanded_search);
-
   if(opt->verbose>2)
     fprintf(console,"gpgkeys: LDAP search for: %s\n",search);
 




More information about the Gnupg-commits mailing list