[Pkg-gnupg-commit] [gnupg2] 141/159: dirmngr: Indicate that serial numbers are hexadecimal.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Jan 27 13:24:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 12c665b36cdc4b7189549698fc4cc1b3523b18f5
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Jan 22 12:54:02 2016 +0100

    dirmngr: Indicate that serial numbers are hexadecimal.
    
    * dirmngr/misc.c (hexify_data): Add arg with_prefix.  Adjust all
    callers.
    * dirmngr/crlcache.c (cache_isvalid): Print "0x" in front of the S/N.
    --
    
    GnuPG-bug-id: 1147
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 dirmngr/crlcache.c |  7 ++++---
 dirmngr/misc.c     | 16 +++++++++++-----
 dirmngr/misc.h     |  2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c
index 13d8a26..25ce7a6 100644
--- a/dirmngr/crlcache.c
+++ b/dirmngr/crlcache.c
@@ -1345,12 +1345,13 @@ cache_isvalid (ctrl_t ctrl, const char *issuer_hash,
       if (n != 16)
         {
           log_error (_("WARNING: invalid cache record length for S/N "));
+          log_printf ("0x");
           log_printhex ("", sn, snlen);
         }
       else if (opt.verbose)
         {
           unsigned char record[16];
-          char *tmp = hexify_data (sn, snlen);
+          char *tmp = hexify_data (sn, snlen, 1);
 
           if (cdb_read (cdb, record, n, cdb_datapos (cdb)))
             log_error (_("problem reading cache record for S/N %s: %s\n"),
@@ -1366,7 +1367,7 @@ cache_isvalid (ctrl_t ctrl, const char *issuer_hash,
     {
       if (opt.verbose)
         {
-          char *serialno = hexify_data (sn, snlen);
+          char *serialno = hexify_data (sn, snlen, 1);
           log_info (_("S/N %s is valid, it is not listed in the CRL\n"),
                     serialno );
           xfree (serialno);
@@ -2095,7 +2096,7 @@ crl_cache_insert (ctrl_t ctrl, const char *url, ksba_reader_t reader)
         err = gpg_error (GPG_ERR_CHECKSUM);
         goto leave;
       }
-    checksum = hexify_data (md5buf, 16);
+    checksum = hexify_data (md5buf, 16, 0);
   }
 
 
diff --git a/dirmngr/misc.c b/dirmngr/misc.c
index c2c5af1..ac3856e 100644
--- a/dirmngr/misc.c
+++ b/dirmngr/misc.c
@@ -59,17 +59,23 @@ hashify_data( const char* data, size_t len )
 {
   unsigned char buf[20];
   gcry_md_hash_buffer (GCRY_MD_SHA1, buf, data, len);
-  return hexify_data( buf, 20 );
+  return hexify_data (buf, 20, 0);
 }
 
 char*
-hexify_data( const unsigned char* data, size_t len )
+hexify_data (const unsigned char* data, size_t len, int with_prefix)
 {
   int i;
-  char* result = xmalloc( sizeof( char ) * (2*len+1));
+  char *result = xmalloc (2*len + (with_prefix?2:0) + 1);
+  char *p;
+
+  if (with_prefix)
+    p = stpcpy (result, "0x");
+  else
+    p = result;
 
-  for( i = 0; i < 2*len; i+=2 )
-    sprintf( result+i, "%02X", *data++);
+  for (i = 0; i < 2*len; i+=2 )
+    snprintf (p+i, 3, "%02X", *data++);
   return result;
 }
 
diff --git a/dirmngr/misc.h b/dirmngr/misc.h
index d8c53d3..be4049e 100644
--- a/dirmngr/misc.h
+++ b/dirmngr/misc.h
@@ -28,7 +28,7 @@ size_t unhexify (unsigned char *result, const char *string);
 char* hashify_data( const char* data, size_t len );
 
 /* Returns data as a hex string. */
-char* hexify_data( const unsigned char* data, size_t len );
+char* hexify_data (const unsigned char* data, size_t len, int with_prefix);
 
 /* Returns the serial number as a hex string.  */
 char* serial_hex ( ksba_sexp_t serial );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list