Skip to content

Commit f2f12ea

Browse files
ebiggersgregkh
authored andcommitted
509: fix printing uninitialized stack memory when OID is empty
[ Upstream commit 8dfd2f2 ] 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: 4f73175 ("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> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9c65a55 commit f2f12ea

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎lib/oid_registry.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize)
116116
int count;
117117

118118
if (v >= end)
119-
return -EBADMSG;
119+
goto bad;
120120

121121
n = *v++;
122122
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)
134134
num = n & 0x7f;
135135
do {
136136
if (v >= end)
137-
return -EBADMSG;
137+
goto bad;
138138
n = *v++;
139139
num <<= 7;
140140
num |= n & 0x7f;
@@ -148,6 +148,10 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize)
148148
}
149149

150150
return ret;
151+
152+
bad:
153+
snprintf(buffer, bufsize, "(bad)");
154+
return -EBADMSG;
151155
}
152156
EXPORT_SYMBOL_GPL(sprint_oid);
153157

0 commit comments

Comments
 (0)