Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2019 23:23:17 +0000 (UTC)
From:      "Simon J. Gerraty" <sjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r348131 - stable/12/lib/libsecureboot/openpgp
Message-ID:  <201905222323.x4MNNH5v062175@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sjg
Date: Wed May 22 23:23:16 2019
New Revision: 348131
URL: https://svnweb.freebsd.org/changeset/base/348131

Log:
  load_key_buf do not free data from dearmor
  
  The data returned by dearmor is referenced by the key
  leave it alone!
  
  MFC r347980
  
  Reviewed by:	stevek

Modified:
  stable/12/lib/libsecureboot/openpgp/opgp_key.c
  stable/12/lib/libsecureboot/openpgp/opgp_sig.c

Modified: stable/12/lib/libsecureboot/openpgp/opgp_key.c
==============================================================================
--- stable/12/lib/libsecureboot/openpgp/opgp_key.c	Wed May 22 23:22:36 2019	(r348130)
+++ stable/12/lib/libsecureboot/openpgp/opgp_key.c	Wed May 22 23:23:16 2019	(r348131)
@@ -168,6 +168,7 @@ load_key_buf(unsigned char *buf, size_t nbytes)
 	initialize();
 
 	if (!(buf[0] & OPENPGP_TAG_ISTAG)) {
+		/* Note: we do *not* free data */
 		data = dearmor((char *)buf, nbytes, &nbytes);
 		ptr = data;
 	} else
@@ -190,7 +191,6 @@ load_key_buf(unsigned char *buf, size_t nbytes)
 			}
 		}
 	}
-	free(data);
 	return (key);
 }
 
@@ -209,8 +209,10 @@ openpgp_trust_add(OpenPGP_key *key)
 
 		LIST_INIT(&trust_list);
 	}
-	if (key)
+	if (key) {
+		DEBUG_PRINTF(2, ("openpgp_trust_add(%s)\n", key->id));
 		LIST_INSERT_HEAD(&trust_list, key, entries);
+	}
 }
 
 /**
@@ -296,6 +298,7 @@ load_key_id(const char *keyID)
 	if (!key)
 		key = load_trusted_key_id(keyID);
 #endif
+	DEBUG_PRINTF(2, ("load_key_id(%s): %s\n", keyID, key ? "found" : "nope"));
 	return (key);
 }
 

Modified: stable/12/lib/libsecureboot/openpgp/opgp_sig.c
==============================================================================
--- stable/12/lib/libsecureboot/openpgp/opgp_sig.c	Wed May 22 23:22:36 2019	(r348130)
+++ stable/12/lib/libsecureboot/openpgp/opgp_sig.c	Wed May 22 23:23:16 2019	(r348131)
@@ -318,6 +318,7 @@ openpgp_verify(const char *filename,
 		sdata = ddata = dearmor((char *)sdata, sbytes, &sbytes);
 	ptr = sdata;
 	rc = decode_packet(2, &ptr, sbytes, (decoder_t)decode_sig, sig);
+	DEBUG_PRINTF(2, ("rc=%d keyID=%s\n", rc, sig->key_id ? sig->key_id : "?"));
 	if (rc == 0 && sig->key_id) {
 		key = load_key_id(sig->key_id);
 		if (!key) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905222323.x4MNNH5v062175>