Remove static print buffer from pgpHexStr, return malloc'ed memory instead
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 7 Apr 2008 10:02:18 +0000 (13:02 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 7 Apr 2008 10:02:18 +0000 (13:02 +0300)
- inlined to get xmalloc() from system.h for consistent malloc fail behavior
- convert callers for new behavior, apart from some debug fprintf()'s

lib/formats.c
lib/rpmchecksig.c
lib/rpmts.c
rpmio/rpmpgp.c
rpmio/rpmpgp.h

index d787a74..f728d62 100644 (file)
@@ -383,7 +383,7 @@ static char * pgpsigFormat(rpmTagType type, rpm_constdata_t data,
            pgpDig dig = pgpNewDig();
            pgpDigParams sigp = &dig->signature;
            size_t nb = 0;
-           const char *tempstr;
+           char *tempstr = NULL;
 
            (void) pgpPrtPkts(pkt, pktlen, dig, 0);
 
@@ -438,6 +438,7 @@ static char * pgpsigFormat(rpmTagType type, rpm_constdata_t data,
            if (t + strlen (tempstr) > val + nb)
                goto again;
            t = stpcpy(t, tempstr);
+           free(tempstr);
 
            dig = pgpFreeDig(dig);
        }
index 7946031..2347487 100644 (file)
@@ -308,9 +308,11 @@ static int rpmReSign(rpmts ts, QVA_t qva, ARGV_const_t argv)
                /* If same signer, skip resigning the package. */
                if (!memcmp(oldsignid, newsignid, sizeof(oldsignid))) {
 
+                   char *signid = pgpHexStr(newsignid+4, sizeof(newsignid)-4);
                    rpmlog(RPMLOG_WARNING,
                        _("%s: was already signed by key ID %s, skipping\n"),
-                       rpm, pgpHexStr(newsignid+4, sizeof(newsignid)-4));
+                       rpm, signid);
+                   free(signid);
 
                    /* Clean up intermediate target */
                    xx = unlink(sigtarget);
index 380028e..fadd4b6 100644 (file)
@@ -403,11 +403,9 @@ rpmRC rpmtsImportPubkey(const rpmts ts, const unsigned char * pkt, size_t pktlen
      || pubp->userid == NULL)
        goto exit;
 
-    v = t = xmalloc(16+1);
-    t = stpcpy(t, pgpHexStr(pubp->signid, sizeof(pubp->signid)));
+    v = pgpHexStr(pubp->signid, sizeof(pubp->signid)); 
 
-    r = t = xmalloc(8+1);
-    t = stpcpy(t, pgpHexStr(pubp->time, sizeof(pubp->time)));
+    t = pgpHexStr(pubp->time, sizeof(pubp->time));
 
     n = t = xmalloc(sizeof("gpg()")+8);
     t = stpcpy( stpcpy( stpcpy(t, "gpg("), v+8), ")");
index 03b369c..7267345 100644 (file)
@@ -204,10 +204,13 @@ static void pgpPrtStr(const char *pre, const char *s)
 
 static void pgpPrtHex(const char *pre, const uint8_t *p, size_t plen)
 {
+    char *hex = NULL;
     if (!_print) return;
     if (pre && *pre)
        fprintf(stderr, "%s", pre);
-    fprintf(stderr, " %s", pgpHexStr(p, plen));
+    hex = pgpHexStr(p, plen);
+    fprintf(stderr, " %s", hex);
+    free(hex);
 }
 
 void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val)
@@ -640,6 +643,13 @@ static const char * const pgpSecretELGAMAL[] = {
 };
 #endif
 
+char * pgpHexStr(const uint8_t *p, size_t plen)
+{
+    char *t = xmalloc(plen * 2 + 1);
+    pgpHexCvt(t, p, plen);
+    return t;
+}
+
 static const uint8_t * pgpPrtPubkeyParams(uint8_t pubkey_algo,
                const uint8_t *p, const uint8_t *h, size_t hlen)
 {
index 6f7c503..96e44ca 100644 (file)
@@ -1049,19 +1049,11 @@ char * pgpHexCvt(char *t, const uint8_t *s, size_t nbytes)
 
 /** \ingroup rpmpgp
  * Return hex formatted representation of bytes.
- * @todo Remove static buffer. 
  * @param p            bytes
  * @param plen         no. of bytes
- * @return             hex formatted string
+ * @return             hex formatted string (malloc'ed)
  */
-static inline
-const char * pgpHexStr(const uint8_t *p, size_t plen)
-{
-    static char prbuf[8*BUFSIZ];       /* XXX ick */
-    char *t = prbuf;
-    t = pgpHexCvt(t, p, plen);
-    return prbuf;
-}
+char * pgpHexStr(const uint8_t *p, size_t plen);
 
 /** \ingroup rpmpgp
  * Return hex formatted representation of a multiprecision integer.