diff options
author | Eric Biggers <ebiggers3@gmail.com> | 2017-12-08 10:13:28 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2017-12-08 10:13:28 -0500 |
commit | 8dfd2f22d3bf3ab7714f7495ad5d897b8845e8c1 (patch) | |
tree | c937db5e51b0f6404d53cb4044e83b8071a8cc51 /lib/oid_registry.c | |
parent | 47e0a208fb9d91e3f3c86309e752b13a36470ae8 (diff) |
509: fix printing uninitialized stack memory when OID is empty
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
"(bad)" to the buffer in the cases where -EBADMSG is returned.
Fixes: 4f73175d0375 ("X.509: Add utility functions to render OIDs as strings")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'lib/oid_registry.c')
-rw-r--r-- | lib/oid_registry.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/oid_registry.c b/lib/oid_registry.c index 5a75d127995d..0bcac6ccb1b2 100644 --- a/lib/oid_registry.c +++ b/lib/oid_registry.c | |||
@@ -116,7 +116,7 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) | |||
116 | int count; | 116 | int count; |
117 | 117 | ||
118 | if (v >= end) | 118 | if (v >= end) |
119 | return -EBADMSG; | 119 | goto bad; |
120 | 120 | ||
121 | n = *v++; | 121 | n = *v++; |
122 | ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40); | 122 | ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40); |
@@ -134,7 +134,7 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) | |||
134 | num = n & 0x7f; | 134 | num = n & 0x7f; |
135 | do { | 135 | do { |
136 | if (v >= end) | 136 | if (v >= end) |
137 | return -EBADMSG; | 137 | goto bad; |
138 | n = *v++; | 138 | n = *v++; |
139 | num <<= 7; | 139 | num <<= 7; |
140 | num |= n & 0x7f; | 140 | num |= n & 0x7f; |
@@ -148,6 +148,10 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) | |||
148 | } | 148 | } |
149 | 149 | ||
150 | return ret; | 150 | return ret; |
151 | |||
152 | bad: | ||
153 | snprintf(buffer, bufsize, "(bad)"); | ||
154 | return -EBADMSG; | ||
151 | } | 155 | } |
152 | EXPORT_SYMBOL_GPL(sprint_oid); | 156 | EXPORT_SYMBOL_GPL(sprint_oid); |
153 | 157 | ||