[Pkg-gnupg-commit] [gnupg2] 155/292: gpg: Replace two sprintf calls.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:37 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 9d6146d6f9870fbfcec15cdc4becaf094d5a90e0
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Oct 24 13:12:05 2016 +0200

    gpg: Replace two sprintf calls.
    
    * g10/keygen.c (print_status_key_created): Use snprintf for now.
    (ask_expire_interval): Replace xmalloc and sprintf by xasprintf.
    --
    
    Future updates: Replace code like
    
       r = xcalloc (1, sizeof *r + 20 );
       r->key = pKEYLENGTH;
       sprintf( r->u.value, "%u", info.key_attr[0].nbits);
    
    by something like
    
       r = new_r_with_value ("%u", info.key_attr[0].nbits);
       r->key = pKEYLENGTH;
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 g10/keygen.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/g10/keygen.c b/g10/keygen.c
index ed529c7..d98b70b 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -180,8 +180,9 @@ print_status_key_created (int letter, PKT_public_key *pk, const char *handle)
           *p++ = ' ';
           fingerprint_from_pk (pk, array, &n);
           s = array;
+          /* Fixme: Use bin2hex */
           for (i=0; i < n ; i++, s++, p += 2)
-            sprintf (p, "%02X", *s);
+            snprintf (p, 3, "%02X", *s);
         }
     }
   if (*handle)
@@ -2428,13 +2429,7 @@ ask_expire_interval(int object,const char *def_expire)
 	  {
 	    char *prompt;
 
-#define PROMPTSTRING _("Signature is valid for? (%s) ")
-	    /* This will actually end up larger than necessary because
-	       of the 2 bytes for '%s' */
-	    prompt=xmalloc(strlen(PROMPTSTRING)+strlen(def_expire)+1);
-	    sprintf(prompt,PROMPTSTRING,def_expire);
-#undef PROMPTSTRING
-
+	    prompt = xasprintf (_("Signature is valid for? (%s) "), def_expire);
 	    answer = cpr_get("siggen.valid",prompt);
 	    xfree(prompt);
 

-- 
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