linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] X.509: fix printing uninitialized stack memory when OID is empty
@ 2017-11-27  7:18 Eric Biggers
  2017-11-28 11:03 ` David Howells
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2017-11-27  7:18 UTC (permalink / raw)
  To: keyrings, David Howells
  Cc: linux-crypto, Alexander Potapenko, Eric Biggers, Takashi Iwai

From: Eric Biggers <ebiggers@google.com>

Callers of sprint_oid() do not check its return value before printing
the result.  In the case where the OID is zero-length, -EBADMSG was
being returned without anything being written to the buffer, resulting
in uninitialized stack memory being printed.  Fix this by writing
"(empty)" to the buffer in that case.

Fixes: 4f73175d0375 ("X.509: Add utility functions to render OIDs as strings")
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/oid_registry.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/oid_registry.c b/lib/oid_registry.c
index 5a75d127995d..3640170f0d65 100644
--- a/lib/oid_registry.c
+++ b/lib/oid_registry.c
@@ -115,8 +115,10 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize)
 	size_t ret;
 	int count;
 
-	if (v >= end)
+	if (v >= end) {
+		snprintf(buffer, bufsize, "(empty)");
 		return -EBADMSG;
+	}
 
 	n = *v++;
 	ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40);
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-28 18:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-27  7:18 [PATCH] X.509: fix printing uninitialized stack memory when OID is empty Eric Biggers
2017-11-28 11:03 ` David Howells
2017-11-28 18:56   ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).